-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebuy.py
47 lines (40 loc) · 1.43 KB
/
rebuy.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
import requests
import gzip
import shutil
import csv
minValue = 5.0
feedURL = 'https://productdata.awin.com/datafeed/download/apikey/f409ea591dbab5db570543a201b9f2f2/language/de/cid/230,609,538/fid/77537,77663/rid/0/hasEnhancedFeeds/0/columns/aw_deep_link,product_name,search_price,ean/format/csv/delimiter/%2C/compression/gzip/adultcontent/1/'
print("Getting URL")
resp = requests.get(feedURL)
print("Done getting URL")
if resp.status_code == 200:
with open("awin_feed.gz", "wb") as file:
print("Starting to write to disk")
file.write(resp.content)
print("File downloaded successfully!")
else:
print("Failed to download the file.")
exit
print("Starting unzip")
with gzip.open('awin_feed.gz', 'rb') as f_in:
with open('awin_feed.csv', 'wb') as f_out:
print("Creating textfile")
shutil.copyfileobj(f_in, f_out)
print("Done unzipping")
cleanList = []
print("Reading lines")
with open("awin_feed.csv", "r", encoding="utf8") as csvfile:
lines = csv.reader(csvfile, delimiter=',')
for line in lines:
try:
price = float(line[2])
except ValueError:
print("Not a number - Next")
continue
if (price >= minValue):
cleanList.append(line)
print("Creating clean csv")
with open('awin_feed_clean.csv', 'w', newline='', encoding="utf8") as newfile:
writer = csv.writer(newfile)
writer.writerows(cleanList)
print("Clean CSV done")