-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.2.py
146 lines (112 loc) · 5.05 KB
/
1.2.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#dependencies
import requests
from bs4 import BeautifulSoup
import csv
from urllib.parse import urlencode
import pandas as pd
import tkinter
import tkinter as tk
from tkinter import messagebox
from tkinter import ttk
root = tk.Tk()
frame_styles = {"relief": "groove",
"bd": 3, "bg": "#BEB2A7",
"fg": "#073bb3", "font": ("Arial", 9, "bold")}
class LoginPage(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
main_frame = tk.Frame(self, bg="#708090", height=431, width=626) # this is the background
main_frame.pack(fill="both", expand="true")
self.geometry("626x431") # Sets window size to 626w x 431h pixels
self.resizable(0, 0) # This prevents any resizing of the screen
title_styles = {"font": ("Trebuchet MS Bold", 16), "background": "blue"}
text_styles = {"font": ("Verdana", 14),
"background": "blue",
"foreground": "#E1FFFF"}
frame_login = tk.Frame(main_frame, bg="blue", relief="groove", bd=2) # this is the frame that holds all the login details and buttons
frame_login.place(rely=0.30, relx=0.17, height=130, width=400)
label_title = tk.Label(frame_login, title_styles, text="Login Page")
label_title.grid(row=0, column=1, columnspan=1)
label_user = tk.Label(frame_login, text_styles, text="Username:")
label_user.grid(row=1, column=0)
label_pw = tk.Label(frame_login, text_styles, text="Password:")
label_pw.grid(row=2, column=0)
entry_user = ttk.Entry(frame_login, width=45, cursor="xterm")
entry_user.grid(row=1, column=1)
entry_pw = ttk.Entry(frame_login, width=45, cursor="xterm", show="*")
entry_pw.grid(row=2, column=1)
button = ttk.Button(frame_login, text="Login", command=lambda: getlogin())
button.place(rely=0.70, relx=0.50)
def getlogin():
username = entry_user.get()
password = entry_pw.get()
# if your want to run the script as it is set validation = True
validation = validate(username, password)
if validation:
tk.messagebox.showinfo("Login Successful",
"Welcome {}".format(username))
root.deiconify()
top.destroy()
else:
tk.messagebox.showerror("Information", "The Username or Password you have entered are incorrect ")
def validate(username, password):
# Checks the text file for a username/password combination.
try:
with open("credentials.txt", "r") as credentials:
for line in credentials:
line = line.split(",")
if line[1] == username and line[3] == password:
return True
return False
except FileNotFoundError:
print("You need to Register first or amend Line 71 to if True:")
return False
def validate_user(username):
# Checks the text file for a username/password combination.
try:
with open("credentials.txt", "r") as credentials:
for line in credentials:
line = line.split(",")
if line[1] == username:
return False
return True
except FileNotFoundError:
return True
#list of URLs
urls = [
'https://www.investing.com/equities/nike'
]
#starting our CSV file
file = open('stockprices.csv', 'w')
writer = csv.writer(file)
writer.writerow(['Company', 'Price', 'Change'])
#looping through our list
for url in urls:
#sending our request through the API
params = {'api_key': 'ae8fe6738115c1cc0121c9498e967c1f', 'url': url}
page = requests.get('http://api.scraperapi.com/', params=urlencode(params))
#our parser
soup = BeautifulSoup(page.text, 'html.parser')
company = soup.find('h1', {'class': 'text-2xl font-semibold instrument-header_title__GTWDv mobile:mb-2'}).text
price = soup.find('div', {'class': 'instrument-price_instrument-price__3uw25 flex items-end flex-wrap font-bold'}).find_all('span')[0].text
change = soup.find('div', {'class': 'instrument-price_instrument-price__3uw25 flex items-end flex-wrap font-bold'}).find_all('span')[2].text
#printing to have some visual feedback
print('Loading :', url)
print(company, price, change)
#writing the data into our CSV file
writer.writerow([company.encode('utf-8'), price.encode('utf-8'), change.encode('utf-8')])
file.close()
data= pd.read_csv("stockprices.csv")
data
data.columns
data.Company
data.Price
data.Change
w = tk.Label(root, text=(data))
top = LoginPage()
top.title("Stocks - Login Page")
root.withdraw()
root.title("Stocks")
root.geometry("400x250")
w.pack()
root.mainloop()