-
Notifications
You must be signed in to change notification settings - Fork 0
/
Multi.py
51 lines (46 loc) · 1.81 KB
/
Multi.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
from multiprocessing import Process
from UpDown import UpDown
from Categories import Categories
from Description import Description
from Upload import Upload
import time
class Multi:
def __init__(self, mission_id=None, db=None):
self.mission_id = mission_id
self.db = db
self.base_url = "http://eol.jsc.nasa.gov/SearchPhotos/"
def uploader(self, updown):
while True:
images = updown.q.get()
if(images):
for image in images:
cat = Categories(image[2])
cat = cat.find_category()
desc = str(image[8]) + ", " + str(image[9])
url = self.base_url + image[1]
date = image[4]
lat = image[5]
lon = image[6]
description = Description(desc, url, date, cat, lat, lon)
print description.get_desc()
up = Upload(description=description, file_name=image[13])
up.perform()
self.db.update_image_uploaded(image[3])
time.sleep(120)
def run(self):
updown = UpDown(db=self.db)
download_procs = []
to_download = self.db.find_rest_images(self.mission_id)
process_2 = Process(
target=updown.up_worker, args=(self.mission_id,))
process_2.start()
process_3 = Process(target=self.uploader, args=(updown,))
process_3.start()
for i in to_download:
while(len(download_procs) > 2):
while(len(download_procs) != 0):
p = download_procs.pop()
p.join()
proccess_1 = Process(target=updown.down_worker, args=(i[1], i[3]))
proccess_1.start()
download_procs.append(proccess_1)