Skip to content

Commit c0208c5

Browse files
committed
calling local launchpad api server
1 parent d3fdb68 commit c0208c5

File tree

5 files changed

+236
-85
lines changed

5 files changed

+236
-85
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ app/test_project.db
6060
app.log
6161

6262
todo.txt
63+
origin-website

logic/scripts/drops.py

+72-48
Original file line numberDiff line numberDiff line change
@@ -20,57 +20,81 @@
2020
"User-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"
2121
}
2222

23-
sites = []
23+
API_ENDPOINT = "http://localhost:3000/api"
2424

25-
API_ENDPOINT = "https://origin-nft-api.com"
25+
def sort_drops(drops):
26+
sorted_drops = sorted(drops, key=lambda x: x.startDate, reverse=True)
27+
return sorted_drops
2628

27-
# def get_drops():
28-
# headers = {
29-
# "Content-Type": "application/json",
30-
# }
31-
# url = "{0}/drops".format(API_ENDPOINT)
29+
def parse_date(date):
30+
return parser.parse(date)
3231

33-
# try:
34-
# with closing(requests.get(url, headers=headers)) as resp:
35-
# if resp.status_code == 200:
36-
# return len(json.loads(resp.content))
37-
# else:
38-
# return None
39-
40-
# except RequestException as e:
41-
# print("Error during requests to {0} : {1}".format(url, str(e)))
42-
# return None
43-
44-
def get_start(drop):
45-
time = parser.parse(drop.start)
46-
return time
47-
48-
def get_drops():
49-
drops = json.loads(open('static/files/drops-mock.json').read(), object_hook=lambda d: SimpleNamespace(**d))
32+
def get_countdown(drop):
33+
current = datetime.now(timezone.utc)
34+
upcoming = parser.parse(drop.startDate)
35+
difference = (upcoming - current).total_seconds()
36+
remaining = difference
37+
38+
day = remaining // (24 * 3600)
39+
remaining = remaining - (day * (24 * 3600))
40+
41+
time = remaining % (24 * 3600)
42+
hour = remaining // 3600
43+
remaining = remaining - (hour * 3600)
44+
45+
time %= 3600
46+
minutes = remaining // 60
47+
countdown = "%dd %dh %dm" % (day, hour, minutes)
48+
return countdown
49+
50+
def filter_upcoming_drops(drops):
51+
upcomingDrops = []
52+
for drop in drops:
53+
if not drop.startDate or not drop.endDate:
54+
continue
55+
if (parse_date(drop.startDate) > datetime.now(timezone.utc) or parse_date(drop.endDate) > datetime.now(timezone.utc)):
56+
drop.countdown = get_countdown(drop)
57+
upcomingDrops.append(drop)
58+
upcomingDrops = sort_drops(upcomingDrops)
5059

51-
sortedDrops = sorted(
52-
drops,
53-
key=lambda x: x.start, reverse=True)
54-
55-
upcomingDrops = sortedDrops[slice(2)]
56-
for upcomingDrop in upcomingDrops:
57-
current = datetime.now(timezone.utc)
58-
upcoming = parser.parse(upcomingDrop.start)
59-
difference = (upcoming - current).total_seconds()
60-
remaining = difference
61-
62-
day = remaining // (24 * 3600)
63-
remaining = remaining - (day * (24 * 3600))
64-
65-
time = remaining % (24 * 3600)
66-
hour = remaining // 3600
67-
remaining = remaining - (hour * 3600)
68-
69-
time %= 3600
70-
minutes = remaining // 60
71-
countdown = "%dd %dh %dm" % (day, hour, minutes)
72-
upcomingDrop.countdown = countdown
73-
74-
pastDrops = sortedDrops[slice(2, len(drops))]
60+
page = 1
61+
return upcomingDrops[slice(0, 2*page)]
62+
63+
def filter_past_drops(drops, allPast):
64+
pastDrops = []
65+
for drop in drops:
66+
if not drop.endDate:
67+
continue
68+
if parse_date(drop.endDate) < datetime.now(timezone.utc):
69+
pastDrops.append(drop)
70+
pastDrops = sort_drops(pastDrops)
71+
72+
if allPast == 'true':
73+
return pastDrops
74+
else:
75+
return pastDrops[slice(0, 3)]
76+
77+
78+
def get_drops(allPast):
79+
80+
headers = {
81+
"Content-Type": "application/json",
82+
}
83+
url = "{0}/site-marketing".format(API_ENDPOINT)
84+
85+
drops = []
86+
try:
87+
with closing(requests.get(url, headers=headers)) as resp:
88+
if resp.status_code == 200:
89+
drops =json.loads(resp.content, object_hook=lambda d: SimpleNamespace(**d))
90+
else:
91+
return None
92+
93+
except RequestException as e:
94+
print("Error during requests to {0} : {1}".format(url, str(e)))
95+
return None
96+
97+
upcomingDrops = filter_upcoming_drops(drops)
98+
pastDrops = filter_past_drops(drops, allPast)
7599

76100
return [upcomingDrops, pastDrops]

static/files/drops-mock.json

+160-35
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,167 @@
11
[
22
{
3-
"upcoming":true,
4-
"title":"Brave",
5-
"subtitle":"Tabong Collection",
6-
"start":"2021-06-10 12:25:56.18-04",
7-
"end":"2021-06-11 12:25:56.18-04",
8-
"image":"https://partner-assets-prod.ogn.app/brave/lg/vintage-art-in-a-hurry-3-x.a208a39e.png"
9-
},
10-
{
11-
"upcoming": true,
12-
"title": "Mike Dean X Shepard Fairey",
13-
"subtitle": "NFT Collection",
14-
"start":"2021-06-11 12:25:56.18-04",
15-
"end":"2021-06-12 12:25:56.18-04",
16-
"image": "https://nft.obey422.com/assets/lg/auction-image.png"
17-
},
18-
{
19-
"upcoming": false,
3+
"id": 1,
4+
"siteId": 1,
5+
"title": "3LAU",
6+
"subtitle": "3LAU Collection",
7+
"image": "https://nft.obey422.com/assets/lg/auction-image.png",
8+
"startDate": "2021-06-20T12:26:24.818Z",
9+
"endDate": "2021-06-21T12:26:24.818Z",
10+
"createdAt": "2021-06-18T12:26:24.818Z",
11+
"updatedAt": "2021-06-18T12:26:24.818Z"
12+
},
13+
{
14+
"id": 2,
15+
"siteId": 2,
16+
"title": "Paris",
17+
"subtitle": "Paris Collection",
18+
"image": "https://nft.obey422.com/assets/lg/auction-image.png",
19+
"startDate": "2021-06-22T12:26:24.818Z",
20+
"endDate": "2021-06-23T12:26:24.818Z",
21+
"createdAt": "2021-06-18T12:26:24.818Z",
22+
"updatedAt": "2021-06-18T12:26:24.818Z"
23+
},
24+
{
25+
"id": 4,
26+
"siteId": 4,
27+
"title": "Jake Paul",
28+
"subtitle": "Jake Paul Collection",
29+
"image": "https://nft.obey422.com/assets/lg/auction-image.png",
30+
"startDate": "2021-06-18T12:26:24.818Z",
31+
"endDate": "2021-06-18T12:26:24.818Z",
32+
"createdAt": "2021-06-18T12:26:24.818Z",
33+
"updatedAt": "2021-06-18T12:26:24.818Z"
34+
},
35+
{
36+
"id": 5,
37+
"siteId": 5,
38+
"title": "Mark",
39+
"subtitle": "Mark Collection",
40+
"image": "https://nft.obey422.com/assets/lg/auction-image.png",
41+
"startDate": "2021-06-18T12:26:24.959Z",
42+
"endDate": "2021-06-18T12:26:24.959Z",
43+
"createdAt": "2021-06-18T12:26:24.959Z",
44+
"updatedAt": "2021-06-18T12:26:24.959Z"
45+
},
46+
{
47+
"id": 6,
48+
"siteId": 6,
49+
"title": "Satoshi Essentials",
50+
"subtitle": "Satoshi Essentials Collection",
51+
"image": "https://nft.obey422.com/assets/lg/auction-image.png",
52+
"startDate": "2021-06-18T12:26:25.073Z",
53+
"endDate": "2021-06-18T12:26:25.073Z",
54+
"createdAt": "2021-06-18T12:26:25.073Z",
55+
"updatedAt": "2021-06-18T12:26:25.073Z"
56+
},
57+
{
58+
"id": 3,
59+
"siteId": 3,
2060
"title": "Lupe Fiasco",
21-
"subtitle": "NFT Collection",
22-
"start":"2021-06-12 12:25:56.18-04",
23-
"end":"2021-06-13 12:25:56.18-04",
24-
"image": "https://nft.lupefiasco.com/static/images/about-img.d7304667.png"
25-
},
61+
"subtitle": "Food and Liquor Collection",
62+
"image": "https://nft.lupefiasco.com/static/images/about-img.d7304667.png",
63+
"startDate": "2021-06-18T12:26:24.818Z",
64+
"endDate": "2021-06-18T12:26:25.093Z",
65+
"createdAt": "2021-06-18T12:26:24.818Z",
66+
"updatedAt": "2021-06-18T12:26:24.818Z"
67+
},
68+
{
69+
"id": 7,
70+
"siteId": 7,
71+
"title": "Ryan Tedder",
72+
"subtitle": "Ryan Tedder Collection",
73+
"image": "https://nft.obey422.com/assets/lg/auction-image.png",
74+
"startDate": "2021-06-18T12:26:25.177Z",
75+
"endDate": "2021-06-18T12:26:25.177Z",
76+
"createdAt": "2021-06-18T12:26:25.177Z",
77+
"updatedAt": "2021-06-18T12:26:25.177Z"
78+
},
79+
{
80+
"id": 8,
81+
"siteId": 8,
82+
"title": "Mike Dean",
83+
"subtitle": "Mike Dean Collection",
84+
"image": "https://nft.obey422.com/assets/lg/auction-image.png",
85+
"startDate": "2021-06-18T12:26:25.294Z",
86+
"endDate": "2021-06-18T12:26:25.294Z",
87+
"createdAt": "2021-06-18T12:26:25.294Z",
88+
"updatedAt": "2021-06-18T12:26:25.294Z"
89+
},
2690
{
27-
"upcoming": false,
91+
"id": 9,
92+
"siteId": 9,
93+
"title": "DudeWithSign",
94+
"subtitle": "DudeWithSign Collection",
95+
"image": "https://nft.obey422.com/assets/lg/auction-image.png",
96+
"startDate": "2021-06-18T12:26:25.378Z",
97+
"endDate": "2021-06-18T12:26:25.378Z",
98+
"createdAt": "2021-06-18T12:26:25.378Z",
99+
"updatedAt": "2021-06-18T12:26:25.378Z"
100+
},
101+
{
102+
"id": 10,
103+
"siteId": 10,
104+
"title": "Brave",
105+
"subtitle": "Brave Collection",
106+
"image": "https://nft.obey422.com/assets/lg/auction-image.png",
107+
"startDate": "2021-06-18T12:26:25.470Z",
108+
"endDate": "2021-06-18T12:26:25.470Z",
109+
"createdAt": "2021-06-18T12:26:25.470Z",
110+
"updatedAt": "2021-06-18T12:26:25.470Z"
111+
},
112+
{
113+
"id": 11,
114+
"siteId": 11,
115+
"title": "Bassjackers",
116+
"subtitle": "Bassjackers Collection",
117+
"image": "https://nft.obey422.com/assets/lg/auction-image.png",
118+
"startDate": "2021-06-18T12:26:25.552Z",
119+
"endDate": "2021-06-18T12:26:25.552Z",
120+
"createdAt": "2021-06-18T12:26:25.552Z",
121+
"updatedAt": "2021-06-18T12:26:25.552Z"
122+
},
123+
{
124+
"id": 12,
125+
"siteId": 12,
28126
"title": "Micro",
29-
"subtitle": "Micro e-bike NFT Collection",
30-
"start":"2021-07-14 12:25:59.18-04",
31-
"end":"2021-07-16 12:25:56.18-04",
32-
"image": "https://nft.micro.com/assets/lg/auction-image.png"
33-
},
34-
{
35-
"upcoming": false,
36-
"title": "Dude With Sign",
37-
"subtitle": "NFT Collection",
38-
"start":"2021-08-14 12:25:57.18-04",
39-
"end":"2021-08-16 12:25:56.18-04",
40-
"image": "https://wtf.dudewithsign.com/assets/lg/collection.png"
127+
"subtitle": "Micro Collection",
128+
"image": "https://nft.obey422.com/assets/lg/auction-image.png",
129+
"startDate": "2021-06-18T12:26:25.643Z",
130+
"endDate": "2021-06-18T12:26:25.643Z",
131+
"createdAt": "2021-06-18T12:26:25.643Z",
132+
"updatedAt": "2021-06-18T12:26:25.643Z"
133+
},
134+
{
135+
"id": 13,
136+
"siteId": 13,
137+
"title": "Builder Demo Site",
138+
"subtitle": "Builder Demo Site Collection",
139+
"image": "https://nft.obey422.com/assets/lg/auction-image.png",
140+
"startDate": "2021-06-18T12:26:25.723Z",
141+
"endDate": "2021-06-18T12:26:25.723Z",
142+
"createdAt": "2021-06-18T12:26:25.723Z",
143+
"updatedAt": "2021-06-18T12:26:25.723Z"
144+
},
145+
{
146+
"id": 14,
147+
"siteId": 14,
148+
"title": "Charlie Bit Me",
149+
"subtitle": "Charlie Bit Me Collection",
150+
"image": "https://nft.obey422.com/assets/lg/auction-image.png",
151+
"startDate": "2021-06-18T12:26:25.802Z",
152+
"endDate": "2021-06-18T12:26:25.802Z",
153+
"createdAt": "2021-06-18T12:26:25.802Z",
154+
"updatedAt": "2021-06-18T12:26:25.802Z"
155+
},
156+
{
157+
"id": 15,
158+
"siteId": 15,
159+
"title": "Kii",
160+
"subtitle": "Kii Collection",
161+
"image": "https://nft.obey422.com/assets/lg/auction-image.png",
162+
"startDate": "2021-06-18T12:26:25.882Z",
163+
"endDate": "2021-06-18T12:26:25.882Z",
164+
"createdAt": "2021-06-18T12:26:25.882Z",
165+
"updatedAt": "2021-06-18T12:26:25.882Z"
41166
}
42167
]

templates/nft.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ <h2>{{gettext("No Past Drops")}}</h2>
5757
{% endif %}
5858
</div>
5959
<div class="d-flex justify-content-center align-items-center">
60-
<a class="mt-6 btn btn-primary d-flex justify-content-center align-items-center" href="https://ousd.com" target="_blank" rel="noreferrer noopener">
60+
<a class="mt-6 btn btn-primary d-flex justify-content-center align-items-center" href="/nft?allPast=true">
6161
{{gettext("View More")}}</a>
6262
</div>div>
6363
</section>

views/web_views.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,8 @@ def dashboard():
629629
@app.route("/nft", strict_slashes=False)
630630
@app.route("/<lang_code>/nft", strict_slashes=False)
631631
def nft():
632-
data = drops.get_drops()
632+
allPast = request.args.get('allPast', None)
633+
data = drops.get_drops(allPast)
633634
return render_template("nft.html", drops=data)
634635

635636
@app.route("/static/css/all_styles.css", strict_slashes=False)

0 commit comments

Comments
 (0)