-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproducts.py
More file actions
executable file
·127 lines (115 loc) · 3.63 KB
/
products.py
File metadata and controls
executable file
·127 lines (115 loc) · 3.63 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
import requests
import re
import json
r = requests.session()
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15'}
def generate_sitelist():
with open('sitelist.txt') as urls:
sitelist = urls.read().splitlines()
return sitelist
def List(url, proxy):
product_urls = []
json_url = 'https://' + url + '/products.json?from=135297231&to=2035543867467'
dump = r.get(json_url, headers = headers, proxies={"http": proxy, "https": proxy})
json_dump = dump.json()
products = json_dump['products']
for product in products:
placeholder = product['handle']
product_url = 'https://' + url + '/products/' + placeholder
product_urls.append(product_url)
return product_urls
# def get_info(url, proxy):
# variants = {}
# resp = r.get(url, headers = headers, proxies={"http": proxy, "https": proxy})
# stock = 'N/A'
# image = 'https://i.imgur.com/PheG08Z.jpg'
# title = 'NO NAME FOUND'
# price = 'N/A'
# try:
# stock = re.findall(r'''"inventory_quantity":(\d*),''', resp.text)
# stock = stock[0]
# except:
# pass
# try:
# jsonurl = url + '.js'
# resp_json = r.get(jsonurl, headers = headers)
# resp_json = json.loads(resp_json.text)
# except:
# print('ERROR LOADING PRODUCT JSON')
# pass
# try:
# images = resp_json['product']['images']
# images = images[0]
# image = images['src']
# except:
# pass
# try:
# title = resp_json['product']['title']
# except:
# pass
# try:
# prices = resp_json['product']['variants']
# for price in prices:
# price = price['price']
# except Exception as e:
# print(e)
# pass
# try:
# variantz = resp_json['product']['variants']
# for variant in variantz:
# vid = variant['id']
# name = variant['title']
# variants[vid] = name
# except Exception as e:
# print(f'ERROR: {e}')
# variants = {"N" : "A"}
# return title, image, stock, price, url, variants
def get_info(url, proxy):
url = url.replace('#restock', '')
variants = {}
resp = r.get(url, headers = headers, proxies={"http": proxy, "https": proxy})
# resp = r.get(url, headers = headers)
try:
stock = re.findall(r'''"inventory_quantity":(\d*),''', resp.text)
stock = stock[0]
except:
stock = 'N/A'
pass
try:
jsonurl = url + '.js'
resp_json = r.get(jsonurl, headers = headers, proxies={"http": proxy, "https": proxy})
resp_json = json.loads(resp_json.text)
except:
print('ERROR LOADING PRODUCT JSON')
pass
try:
image = resp_json['images'][0]
image = f'https:{image}'
except:
image = 'https://i.imgur.com/PheG08Z.jpg'
pass
try:
title = resp_json['title']
except:
title = 'NO NAME FOUND'
pass
try:
prices = resp_json['variants']
for price in prices:
price = price['price']
except Exception as e:
print(e)
price = 'N/A'
pass
try:
variantz = resp_json['variants']
for variant in variantz:
if variant['available'] == True:
vid = variant['id']
name = variant['title']
variants[vid] = name
else:
pass
except Exception as e:
print(f'ERROR: {e}')
return title, image, stock, price, url, variants