diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Billy_BOY_ALPHA.py b/Billy_BOY_ALPHA.py index ee195a8..2656e48 100644 --- a/Billy_BOY_ALPHA.py +++ b/Billy_BOY_ALPHA.py @@ -4,6 +4,8 @@ from urllib import parse import json import time +import os + ################################## MAIN CODE ############################################### @@ -13,12 +15,12 @@ # Change Values *required: #CO/MAGTI -Username = 'YOUR CO/MAGTI USERNAME' -Password = 'YOUR CO/MAGTI PASSWORD' +Username = 'guja001' +Password = 'anastasia001' ### #Telasi -Telasi_id = 'ID' +Telasi_id = '653145' ########################### @@ -100,5 +102,7 @@ pay_day_water = pay_day_water_filter[-1] +os.system('notify-send "TITLE" "MESSAGE"') + print(pay_day_water) \ No newline at end of file diff --git a/Main_Billy.py b/Main_Billy.py new file mode 100644 index 0000000..7ac884f --- /dev/null +++ b/Main_Billy.py @@ -0,0 +1,60 @@ +import os +import time +import random +import magti +import telasi + + +# Change Values *required: + +#CO/MAGTI +Username = 'YOUR CO/MAGTI USERNAME' +Password = 'YOUR CO/MAGTI PASSWORD' +### + +#Telasi +Telasi_id = 'ID' + + +# Notify me to pay + + +until_its_left = 3 # days + +now = time.strftime("%d.%m.%Y") + +# running external py functions + +print('telasi = ',telasi.telasi_bil(Telasi_id, now)) + +print('magti = ',magti.magti_bil(Username,Password,now)) + + +# end of running them + +def notifications(From,Message): + os.system('notify-send "%s" "%s"' % (From, Message)) + +notifications(telasi.telasi_bil(Telasi_id, now)[0],telasi.telasi_bil(Telasi_id, now)[1]+' left\n' + +str(telasi.telasi_bil(Telasi_id, now)[2])+' ლარი') + +notifications(magti.magti_bil(Username,Password,now)[0],magti.magti_bil(Username,Password,now)[1]+' left\n' + +str(magti.magti_bil(Username,Password,now)[2]) +' ლარი') + + +while True: + + if int(telasi.telasi_bil(Telasi_id, now)[1][:2]) <= until_its_left or int(magti.magti_bil(Username,Password,now)[1][:2]) <= until_its_left: + + os.system("gnome-terminal -e 'python ./payment.py'") + + break + + else: + + hr_in_sec = [10800, 7200] # 3 or 2 + + notifications('Billy','I go sleep') + + time.sleep(random.choice(hr_in_sec)) + diff --git a/magti.py b/magti.py new file mode 100644 index 0000000..70dfc06 --- /dev/null +++ b/magti.py @@ -0,0 +1,67 @@ +from datetime import datetime +from bs4 import BeautifulSoup +import requests +from urllib import parse +import json + + +def magti_bil(co__username, co__password , now): + session = requests.Session() + session.cookies.get_dict() + + frst_post = session.post("https://userarea.magticom.ge", data={'UserName': co__username, 'Password': co__password}) + + frst_view = BeautifulSoup(frst_post.text, 'lxml') + + attrs = {} + for vals in frst_view.findAll('input'): + attrs[vals['id'][3:]] = vals['value'] + + attrs['TabIndex'] = '0' + + headers = { + 'Accept': '*/*', + 'Accept-Encoding': 'gzip, deflate, br', + 'Accept-Language': 'en-US,en;q=0.8,ru;q=0.6,ka;q=0.4', + 'Cache-Control': 'no-cache', + 'Connection': 'keep-alive', + 'Content-Length': '84', + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': '__utma=142200110.405086356.1478026025.1478467079.1481496629.3; _ga=GA1.2.405086356.1478026025; ' + 'ASP.NET_SessionId=%(ASP.NET_SessionId)s' % session.cookies.get_dict(), + 'Host': 'userarea.magticom.ge', + 'Origin': 'https://userarea.magticom.ge', + 'Pragma': 'no-cache', + 'Referer': '%s' % frst_post.url, + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36', + 'X-Requested-With': 'XMLHttpRequest', + } + + scnd_post = requests.post('https://userarea.magticom.ge/Services/LoadTab', data=parse.urlencode(attrs).encode(), + headers=headers) + + scnd_view = BeautifulSoup(scnd_post.text, 'html.parser') + + eaten = json.loads(scnd_view.text) + + third_view = BeautifulSoup(eaten['Data'], 'html.parser') + + dirty_p = third_view.findAll('p') + clean_p = [] + + for clean in dirty_p: + clean_p.append(clean.text) + + latest_dict = dict([(k, v) for k, v in zip(clean_p[::2], clean_p[1::2])]) + + pay_day = latest_dict['გათიშვის თარიღი'] + + pay_day = datetime.strptime(pay_day, "%d.%m.%Y") + + now = datetime.strptime(now, "%d.%m.%Y") + + time = pay_day - now + + ret_list = ['CO/Magti',str(time)[:7], latest_dict['ბალანსი']] + + return ret_list \ No newline at end of file diff --git a/payment.py b/payment.py new file mode 100644 index 0000000..0d2339b --- /dev/null +++ b/payment.py @@ -0,0 +1,9 @@ +import os + + +inp = input("Do you want me to pay bills?") + +if inp == 'Y': + print("Can't do this right now") + +# Here will be added support of online banking when I'll have time \ No newline at end of file diff --git a/telasi.py b/telasi.py new file mode 100644 index 0000000..7350370 --- /dev/null +++ b/telasi.py @@ -0,0 +1,35 @@ +from datetime import datetime +from bs4 import BeautifulSoup +import requests + + +def telasi_bil (ID,now): + frst_post = requests.get('http://my.telasi.ge/customers/info/%s' % ID) + soup = BeautifulSoup(frst_post.text,'html.parser') + + result = [] + for code in soup.findAll('code'): + result.append(code.text) + + + result = [float(i) for i in result[1:4]] + + + pay_day_water_filter = [] + + for ultag in soup.find_all('div', {'class': 'pull-right'}): + pay_day_water_filter.append(ultag.text) + + bill_for_water = sum(result) + + pay_day = pay_day_water_filter[-1] + + pay_day = datetime.strptime(pay_day.strip(), "%d/%m/%Y") + + now = datetime.strptime(now, "%d.%m.%Y") + + time = pay_day - now + + ret_list = ['Telasi',str(time)[:6], bill_for_water] + + return ret_list