-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_forex.py
executable file
·69 lines (53 loc) · 1.78 KB
/
demo_forex.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
#! /usr/bin/env python
# -*- coding: UTF-8 -*-
import drivers
import time
import requests
import datetime
import bs4
display = drivers.Lcd()
sleepSecond = 1
minute = 60
iteration = minute/sleepSecond
selectedCurrencyList = ["USD/TRY", "EUR/TRY", "EUR/USD", "GAU/TRY", u"BİST 100"]
fakeHeaders = {
'User-Agent': 'Google Chrome'
}
def GetTime():
currentTime = datetime.datetime.now()
return currentTime.strftime("%d.%m %a %H:%M")
def PrintTime():
display.lcd_display_string(GetTime(), 1)
def PrintCurrency(currency):
display.lcd_display_string(currency, 2)
def PrintScreen(currency):
display.lcd_clear()
PrintTime()
PrintCurrency(currency)
def GetCurrencyList():
htmlResponse = requests.get(url="https://tr.investing.com/", headers=fakeHeaders)
html = htmlResponse.content
parsedHtml = bs4.BeautifulSoup(html, features="html.parser")
htmlCurrencyList = parsedHtml.findAll("tr", {"class": "LeftLiContainer"})
currencyTextList = list()
for htmlCurrency in htmlCurrencyList:
currencyName = htmlCurrency.find("td", {"class": "left bold first noWrap"}).find("a").text
currencyValue = htmlCurrency.find("td", {"class": "lastNum"}).text
if currencyName in selectedCurrencyList:
currencyTextList.append(currencyName + " " + currencyValue)
return currencyTextList
try:
while True:
currencyList = GetCurrencyList()
if currencyList:
for i in range(int(iteration/len(currencyList))):
for item in currencyList:
PrintScreen(item)
time.sleep(sleepSecond)
else:
display.lcd_clear()
PrintTime()
time.sleep(sleepSecond)
except KeyboardInterrupt:
print("Cleaning up!")
display.lcd_clear()