-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
107 lines (100 loc) · 3.31 KB
/
Copy pathdata.py
File metadata and controls
107 lines (100 loc) · 3.31 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""
Created by: Arman B (techtide) && SRugina
Purpose: Makes using data from the NASA APIs as easy as modifying a configuration file.
Date: 11/10/2018
"""
from run import *
import requests
import json
import urllib.request
import tkinter as tk
from PIL import ImageTk, Image
def show_imge(path):
image_window = tk.Tk()
imgr = Image.open(path)
imgr = imgr.resize((1280,720), Image.ANTIALIAS)
img = ImageTk.PhotoImage(imgr)
panel = tk.Label(image_window, image=img, height=720, width=1280)
panel.pack(side="bottom", fill="both", expand="yes")
image_window.mainloop()
array1 = [] # this has the labels
trainortestval = str(get_train_or_test())
if (get_data_type() == 'image'):
i = 1
r1 = requests.get(get_request_url())
h1 = json.loads(str(r1.text))
d1 = h1["date"]
dval = int(d1[-2:])
opznum = 10
while i <= 20:
print(get_request_url())
rurl = get_request_url()
r = requests.get(get_request_url())
h = json.loads(str(r.text))
d = h["date"]
opz = ""
if (dval < opznum):
opz = "0"
else:
opz = ""
d2 = d[:-2] + opz + str(dval)
if ("hdurl" not in h):
print("not img")
dval = dval+1
if (dval < opznum):
opz = "0"
else:
opz = ""
d2 = d[:-2] + opz + str(dval)
set_request_url(rurl[:-10] + d2)
continue
else:
temparray = [0, 0, 0]
imgurl = h["hdurl"]
imgnum = i
urllib.request.urlretrieve(imgurl, trainortestval + "/" + str(imgnum) + ".jpg")
show_imge(trainortestval + "/" + str(imgnum) + ".jpg")
print(h["explanation"])
labelornot = int(input("Which label should we assign? (0=skip image, 1=" + str(get_labels()[0]) + ", 2=" + str(get_labels()[1]) + ", 3=" + str(get_labels()[2]) + ", 4=" + str(get_labels()[3])))
if labelornot != 0:
temparray[0] = trainortestval + "/" + str(imgnum) + ".jpg"
label_options = get_labels()
labelstr = str(get_labels()[labelornot-1])
labelstr = labelstr[2:]
labelstr = labelstr[:-2]
temparray[1] = labelstr
temparray[2] = trainortestval
array1.append(temparray)
print(imgurl)
dval = dval+1
if (dval < opznum):
opz = "0"
else:
opz = ""
d2 = d[:-2] + opz + str(dval)
else:
os.remove(trainortestval + "/" + str(imgnum) + ".jpg")
dval = dval+1
if (dval < opznum):
opz = "0"
else:
opz = ""
d2 = d[:-2] + opz + str(dval)
set_request_url(rurl[:-10] + d2)
continue
set_request_url(rurl[:-10] + d2)
i = i+1
if i > 20:
print(array1)
elif (get_data_type() == 'text'):
#pseudo code
r1 = requests.get(get_request2_url())
h1 = json.loads(str(r1.text))
d1 = h1["diameter"]
l1 = h1["type"]
temparray = [0, 0, 0]
temparray[0] = d1
temparray[1] = l1
temparray[2] = trainortestval
array1.append(temparray)
print(array1)