-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_palettes.py
31 lines (23 loc) · 936 Bytes
/
get_palettes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import json
import requests
import urllib.request
# from skimage import io, color
f = open("compat_set.csv", 'a')
# f.write('artist,paletteId,previewImage,rating,palette\n')
for i in range(11,12): #, 'orderCol': "numVotes", 'sortBy': 'DESC'
res = requests.get("https://www.colourlovers.com/api/palettes", params={"format": "json", "numResults": 100, 'resultOffset': i * 100, 'orderCol': "numViews", 'sortBy': 'ASC'})
palettes = res.json()
for p in palettes:
if len(p['colors']) == 0:
continue
hearts = p['numVotes']
views = p['numViews']
r = (hearts - (0.0152 * views - 0.263)) / (0.0128 * views + 0.218) + 3
if r > 5:
r = 5
print(p["id"], r)
# f.write(p["userName"] + ',' + str(p['id']) + ',' + p['url'] + ',' + str(r) + ',')
# for c in p["colors"]:
# f.write(str(c) + " ")
# f.write('\n')
f.close()