forked from fbessez/Tinder
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgatherimages.py
83 lines (65 loc) · 2.49 KB
/
gatherimages.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from datetime import date, datetime
from random import random
from time import sleep, time
import os
import config
import tinder_api as api
import features as feat
# import cv2
from PIL import Image
import urllib
from io import StringIO
import config
import json
import foldercount
import progressbar
if api.authverif() == True:
print("Gathering images from nearby users for training...")
# print(api.get_self())
y = 1
repeats = []
# Create images folder if necessary
if not os.path.isdir('./images'):
os.makedirs('./images')
while foldercount.numfile("./images/") < 1000:
sleep(0.5)
print(foldercount.numfile('./images/'))
search = api.get_recs_v2()
try:
ppl= search['data']['results']
for i in range(len(ppl)):
if ppl[i]['user']['_id'] in repeats:
pass
else:
pics = feat.get_photos(ppl[i]['user'])
path = './images/'
for j in pics:
x = foldercount.numfile(path)+1
file = urllib.request.urlopen(j)
img = Image.open(file)
img.save(path+'userpic'+str(x)+".jpg",'JPEG')
repeats.append(ppl[i]['user']['_id'])
except KeyError:
print("Key error...")
print("Gathering images for predictions")
# Create prediction folder if necessary
if not os.path.isdir('./prediction'):
os.makedirs('./prediction')
while foldercount.numfile("./prediction/") < 100:
sleep(0.5)
search = api.get_recs_v2()
ppl= search['data']['results']
for i in range(len(ppl)):
if ppl[i]['user']['_id'] in repeats:
pass
else:
pics = feat.get_photos(ppl[i]['user'])
path = './prediction/'
for j in pics:
x = foldercount.numfile(path)+1
file = urllib.request.urlopen(j)
img = Image.open(file)
img.save(path+'userpic'+str(x)+".jpg",'JPEG')
repeats.append(ppl[i]['user']['_id'])
else:
print("Something went wrong. You were not authorized.")