Skip to content

Commit

Permalink
Updated.
Browse files Browse the repository at this point in the history
Got code some structure.

added features

*notifications
*can ran background

supports ubuntu 16.04
  • Loading branch information
JexPY committed Sep 26, 2017
1 parent 3896a4b commit 8607183
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions Billy_BOY_ALPHA.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from urllib import parse
import json
import time
import os



################################## MAIN CODE ###############################################
Expand All @@ -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'

###########################

Expand Down Expand Up @@ -100,5 +102,7 @@

pay_day_water = pay_day_water_filter[-1]

os.system('notify-send "TITLE" "MESSAGE"')


print(pay_day_water)
60 changes: 60 additions & 0 deletions Main_Billy.py
Original file line number Diff line number Diff line change
@@ -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))

67 changes: 67 additions & 0 deletions magti.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions payment.py
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions telasi.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8607183

Please sign in to comment.