-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-bourse-price.py
39 lines (28 loc) · 807 Bytes
/
get-bourse-price.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
import sys
text_file = open("list-bourse-csv.txt", "r")
lines = text_file.read().split()
text_file.close()
from os.path import basename
import os
from urllib.parse import urlsplit
import urllib.request
def url2name(url):
return basename(urlsplit(url)[2])
def download(url, out_path):
localName = url2name(url)
req = urllib.request.Request(url)
r = urllib.request.urlopen(req)
localName = url.split("=")[-1]+".csv"
localName = os.path.join(out_path, localName)
f = open(localName, 'wb+')
f.write(r.read())
f.close()
fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'bourse_price')
for line in lines:
try:
download(line, fn)
except KeyboardInterrupt:
print("Bye")
sys.exit()
except:
print("Failed "+line)