Repository navigation
Expand file tree
/
Copy pathScript-022_DownloadBviewFiles - multithreading-optimized.py
More file actions
136 lines (126 loc) · 5.84 KB
/
Copy pathScript-022_DownloadBviewFiles - multithreading-optimized.py
File metadata and controls
136 lines (126 loc) · 5.84 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import urllib.request
import httplib2
import _thread
import time
import re
#########################################
# thread function for ris data download #
#########################################
def download(rrc,name):
id = _thread.get_ident()
print("start thread",id,"||",rrc,"-",name)
print()
# definition of start time
date_start = (2010,1,1,0,0,0,0,0,0)
date_start_absolut = time.mktime(date_start)
date_start_localtime = time.localtime(date_start_absolut)
date_start_directory = time.strftime("%Y.%m",date_start_localtime)
date_start_compare = time.strftime("%Y%m%d",date_start_localtime)
# definition of start doublet
doublet_start = (2009,12,31,0,0,0,0,0,0)
doublet_start_absolut = time.mktime(doublet_start)
doublet_start_localtime = time.localtime(doublet_start_absolut)
doublet_start_directory = time.strftime("%Y.%m",doublet_start_localtime)
doublet_start_compare = time.strftime("%Y%m%d",doublet_start_localtime)
# parsing RIS "raw data website"
directory = True
treffer = 0
doublet = doublet_start_compare
while directory == True:
url = "http://data.ris.ripe.net/" + rrc + "/" + date_start_directory + "/"
h = httplib2.Http(".cache")
header, content = h.request(url,"GET")
content_string = content.decode(encoding='utf-8')
list_bview = re.findall(r"href\=\"(bview\.20[0-3][0-9][0-1][0-9][0-3][0-9]\..*?)\"",
str(content_string))
list_bview.reverse()
print()
print(list_bview)
print()
# find first bview of the day in start directory (first month)
for index in list_bview:
print()
print("index for loop:",index)
print()
if doublet == doublet_start_compare:
print("do nothing in first if fork - part1:")
print()
elif index[6:14] == doublet:
print("do nothing in first if fork - part 2:")
print()
elif index[6:14] > doublet:
print("index[6:14] in first if fork - part 3:",index[6:14])
print("doublet in first if fork - part 3:",doublet)
date_start_absolut += 86400
date_start_localtime = time.localtime(date_start_absolut)
date_start_compare = time.strftime("%Y%m%d",date_start_localtime)
treffer = 0
print("treffer in first if fork - part 3:",treffer)
print("index[6:14] in first if fork - part 3:",index[6:14])
print("date_start_compare in first if fork - part 3:",date_start_compare)
print()
compare = False
while compare == False:
if index[6:14] == date_start_compare:
print("index[6:14] if fork start:",index[6:14])
print("date_start_compare start:",date_start_compare)
while treffer == 0:
print("index[6:14] while loop start:",index[6:14])
print("date_start_compare start:",date_start_compare)
doublet = index[6:14]
print("doublet:",doublet)
download_url = url + index
print("download_url:",download_url)
download_file = urllib.request.urlopen(download_url)
download_data = download_file.read()
with open("D:/Python/" + rrc + "/" + index,"wb") as code:
code.write(download_data)
print("index[6:14] while loop end:",index[6:14])
print("date_start_compare end:",date_start_compare)
treffer += 1
compare = True
print("index[6:14] if fork end:",index[6:14])
print("date_start_compare end:",date_start_compare)
print()
else:
print("index[6:14] else fork start:",index[6:14])
print("date_start_compare start:",date_start_compare)
if index[6:14] < date_start_compare:
directory = False
break
date_start_absolut += 86400
date_start_localtime = time.localtime(date_start_absolut)
date_start_compare = time.strftime("%Y%m%d",date_start_localtime)
print("index[6:14] else fork end:",index[6:14])
print("date_start_compare end:",date_start_compare)
print()
if directory == False:
break
# find first bview of the day in the next directory (next month)
print()
print("change to new month")
print("===================")
date_directory_absolute = date_start_absolut + 86400
date_directory_localtime = time.localtime(date_directory_absolute)
date_start_directory = time.strftime("%Y.%m",date_directory_localtime)
print("date_start_absolut:",date_start_absolut)
print("date_directory_absolute:",date_directory_absolute)
print("date_start_directory:",date_start_directory)
print("end of thread",id,"||",rrc,"-",name)
return
#############################################
# main program for downloading RIS raw data #
#############################################
global ixp_dic
ixp_dic = {"rrc01":"LINX","rrc07":"Netnod","rrc10":"MIX","rrc12":"DE-CIX","rrc13":"MSK-IX"}
ixp_abbr = ixp_dic.keys()
ixp_name = ixp_dic.values()
id = _thread.get_ident()
print("start main program: ",id)
print()
# starting one thread for each remote route collector
for rrc in ixp_abbr:
print("download RIS data from",rrc,ixp_dic[rrc])
name = ixp_dic[rrc]
_thread.start_new_thread(download,(rrc,name))
time.sleep(0.1)