-
Notifications
You must be signed in to change notification settings - Fork 0
/
currency.py
85 lines (54 loc) · 2.06 KB
/
currency.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
from colorama import Fore,Back,Style,init,deinit
from bs4 import BeautifulSoup
import requests
import time
import sys
init()
banner = '''
__ __ __ ___ __ __ ___ __ ___ __
/ ` | | |__) |__) |__ |\ | / ` \ / __ / ` |__| |__ / ` |__/ |__ |__)
\__, \__/ | \ | \ |___ | \| \__, | \__, | | |___ \__, | \ |___ | \
author : Ahmet Yigit AYDENIZ
'''
if len(sys.argv) <= 1:
print(banner)
exit()
else:
print('\n'+ banner +'\n')
if sys.argv[1] == 'list':
while True:
with open ("stocks.txt", "r") as myfile:
data = myfile.read().splitlines()
for i in data:
url = "https://www.google.com/search?q="+i+"+price"
HTML = requests.get(url)
named_tuple = time.localtime()
time_string = time.strftime("%m/%d/%Y, %H:%M:%S", named_tuple)
soup = BeautifulSoup (HTML. text, 'html.parser')
text = soup.find("div", attrs={'class': 'BNeawe iBp4i AP7Wnd'}).find("div", attrs={'class': 'BNeawe iBp4i AP7Wnd'}).text
if '+' in text:
print(i + Fore.GREEN +' '+text+Fore.RESET+' '+time_string)
elif '-' in text:
print(i + Fore.RED +' '+ text +Fore.RESET+' '+time_string)
else:
print(i + Fore.YELLOW +' [price] -> '+ text +Fore.RESET+' '+time_string)
else:
print("")
time.sleep(3)
else:
stock = sys.argv[1]
url = "https://www.google.com/search?q="+stock+"+price"
while True:
HTML = requests.get(url)
named_tuple = time.localtime()
time_string = time.strftime("%m/%d/%Y, %H:%M:%S", named_tuple)
soup = BeautifulSoup (HTML. text, 'html.parser')
text = soup.find("div", attrs={'class': 'BNeawe iBp4i AP7Wnd'}).find("div", attrs={'class': 'BNeawe iBp4i AP7Wnd'}).text
if '+' in text:
print(stock + Fore.GREEN +' '+text+Fore.RESET+' '+time_string)
elif '-' in text:
print(stock + Fore.RED +' '+ text +Fore.RESET+' '+time_string)
else:
print(stock + Fore.YELLOW +' [price] -> '+ text +Fore.RESET+' '+time_string)
time.sleep(3)
deinit()