forked from arielya10/AliExpress-Order-Tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan.py
133 lines (114 loc) · 4.44 KB
/
scan.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
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
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.support import expected_conditions as EC
from forex_python.converter import CurrencyRates
import time
import pyfiglet
cr=CurrencyRates()
print(pyfiglet.figlet_format("AliExpress BOT"))
#Login
def login():
while True:
user_email=input("Enter your mail: ")
user_password=input("Enter your password: ")
email = driver.find_element(By.ID, 'fm-login-id')
email.clear()
email.send_keys(user_email)
password = driver.find_element(By.ID, 'fm-login-password')
password.clear()
password.send_keys(user_password)
driver.find_element(By.XPATH, '//*[@id="root"]/div/div/div/div[2]/div/div/button[2]').click()
time.sleep(5)
try:
driver.find_element(By.XPATH, '//*[@id="root"]/div/div/div/div[2]/div/div/button[2]').click()
print("Your account name or password is incorrect.")
driver.close()
driver.quit()
exit()
except Exception:
driver.maximize_window()
break
#Showing all the items
def show_all_orders(flag):
while True:
try:
view_orders = wait.until(EC.visibility_of_element_located((By.XPATH,f'//*[@id="root"]/div/div[2]/div[{flag}]/button/span')))
driver.execute_script("arguments[0].click();", view_orders)
except Exception:
break
#Counting orders
def get_orders(flag):
i = 1
counter=1
total_price = 0
tab="My orders"
span="span"
if flag==2:
tab= "Deleted orders"
span="label/span[2]"
while True:
try:
#Getting statuses {Finished , Awaiting delivery} not acceptable statuses {Closed, Cancelled}
status = driver.find_element(By.XPATH,f'//*[@id="root"]/div/div[2]/div[{flag}]/div/div[{i}]/div[1]/div[1]/{span}')
status =status.text
if status == "Finished" and status != "Awaiting delivery":
#Getting item price
order =driver.find_element(By.XPATH,f'//*[@id="root"]/div/div[2]/div[{flag}]/div/div[{i}]/div[3]/div[2]/div[1]/span')
driver.execute_script("arguments[0].scrollIntoView();", order)
order =order.text
#Checking currency
if order.find('₪') != -1:
order = order.replace('Total: ₪ ', '')
price=float(order)
price = cr.convert('ILS', 'USD', price)
else:
order = order.replace('Total: US $', '')
price=float(order)
#Summing total price
counter += 1
total_price += price
print(f"({tab})({status}) Total money spent: {total_price:.2f}$, Price: {price:.2f}$, (index: {counter})\n")
i+=1
except Exception:
break
print(f"Total money spent in {tab}: {total_price:.2f}$\n")
print(f"{counter} items bought...\n")
return total_price,counter
#URL and browser
while True:
print("What browser are you using ? \n")
print("1) Chrome\n")
print("2) Firefox\n")
try:
browser=int(input("Enter your choice: "))
if browser==1:
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
break
elif browser==2:
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
break
else:
print("Enter valid option...\n")
except Exception:
print("Enter valid option...\n")
driver.minimize_window()
driver.get('https://www.aliexpress.com/p/order/index.html')
wait = WebDriverWait(driver, 5)
#Login
login()
#Getting my orders
show_all_orders(2)
sum_my_orders=get_orders(1)
#Getting deleted orders
deleted_orders = wait.until(EC.visibility_of_element_located((By.XPATH,'//*[@id="root"]/div/div[1]/div[1]/div[2]')))
driver.execute_script("arguments[0].click();", deleted_orders)
show_all_orders(3)
sum_deleted_orders=get_orders(2)
print(f"Total money spent in Aliexpress: {sum_my_orders[0] + sum_deleted_orders[0]:.2f}$")
print(f"{sum_my_orders[1] + sum_deleted_orders[1]} items bought.....")
driver.close()
driver.quit()