-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamiami.py
89 lines (76 loc) · 2.68 KB
/
amiami.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
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
#!/usr/bin/env python3
from selenium import webdriver
import random, json, csv
import time
from bs4 import BeautifulSoup
from contextlib import redirect_stdout
wantedFigs = []
wishlist = {}
def loadWishList():
global wishlist
with open ('wanted.json', 'r') as fp:
wishlist = json.load(fp)
def repeator(preowned):
while(True):
random_wait_time = random.randrange(900, 1200)
time.sleep(random_wait_time)
loadWishList()
preowned = checkPreowned("https://www.amiami.com/eng/search/list/?s_st_condition_flg=1&s_sortkey=preowned&pagecnt=")
display(preowned)
preowned = clean_up(preowned)
def checkPreowned(url):
preownedFigs = {}
random_wait_time = random.randrange(5.0, 15.0)
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
# options.binary_location = "/snap/bin/chromium"
wd = webdriver.Chrome(chrome_options=options)
curPage = 1
currentURL = url + str(curPage)
wd.get(currentURL)
time.sleep(random_wait_time)
soup = BeautifulSoup(wd.page_source,features="html.parser")
cleaned_soup = checkIndiPage(soup)
stringProcessing(cleaned_soup, preownedFigs)
while(cleaned_soup != ""): #cleaned_soup != ""
random_wait_time = random.randrange(5.0, 15.0)
curPage = curPage + 1
currentURL = url + str(curPage)
wd.get(currentURL)
time.sleep(random_wait_time)
soup = BeautifulSoup(wd.page_source,features="html.parser")
cleaned_soup = checkIndiPage(soup)
preownedFigs = stringProcessing(cleaned_soup, preownedFigs)
return preownedFigs
def checkIndiPage(soup):
for data in soup.find_all('div', {'class':'wrapper'}):
for ulTag in data.find_all('ul', {'class':'new-items__inner'}):
return ulTag.text
def stringProcessing(input, preownedFigs):
global wantedFigs, wishlist
parsed1 = []
if(input):
items = input.split("\n")
for item in items:
item = item.strip()
index = item.find("Closed")
if(index != -1):
item = item[index:]
item = item.replace("Closed", "", 1)
if (item in wishlist):
preownedFigs[item] = wishlist.get(item)
return preownedFigs
def display(preowned):
if(preowned):
print(preowned)
else :
print("No matches")
def clean_up(preowned):
preowned.clear()
return preowned
loadWishList()
preowned = checkPreowned("https://www.amiami.com/eng/search/list/?s_st_condition_flg=1&s_sortkey=preowned&pagecnt=")
display(preowned)
preowned = clean_up(preowned)
repeator(preowned)