Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf8 -*-
- __author__ = 'n00bcoder'
- '''module to create on-screen widget to show MegaFon balance from corporate account and switch cellular lines to IP mode
- Module will be very useful to those, who have IP-PBX with many connected lines and need to see balance in real-time, to control expences
- and to stop SIP-attacks in time, for example, when you see, that your balance spends nearly at the light speed you could easily go and power off
- your PBX-server. With a gun, if you would like to.=)'''
- import urllib
- import urllib2
- import lxml
- import lxml.html
- import cookielib
- import Tkinter
- class App: # It is a class-based application
- def __init__(self):
- self.root = Tkinter.Tk() # It is a tk application
- self.root.attributes("-toolwindow", 1) # With a single border and without buttons except "close"
- self.root.wm_attributes("-topmost", 1) # And always topmost (except most topmost cases, of course =))
- self.var = Tkinter.StringVar() #And with a var to get text from outside
- self.label = Tkinter.Label(self.root, textvariable=self.var) # With a label, of course, to show your precious balance (mah precious, kekeke)
- self.response=urllib2.urlopen('https://sm.megafon.ru/sm/client/routing/[email protected]&password=somepass&routing=1') # With an ability to change line state into LINE_STATE_SIP
- self.response=urllib2.urlopen('https://sm.megafon.ru/sm/client/routing/[email protected]&password=somepass&routing=1') # Not even one line state =)
- self.log = 'CP_9241234567' # With a built-in login (will be in separate config file on the next version)
- self.pas = '50me10nnandstr0NNPas5w0rd' # And built-in password (will be in separate config file too)
- self.cookie = cookielib.CookieJar() # With an ability to store cookies
- self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie)) # And process them
- urllib2.install_opener(self.opener)
- self.headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 5.1; rv:38.0) Gecko/20100101 Firefox/38.0',
- 'Accept': 'application/json, text/javascript, */*; q=0.01',
- 'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
- 'Accept-Encoding': 'gzip, deflate',
- 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
- 'X-Requested-With': 'XMLHttpRequest'} # It can even transfer headers, like Mozilla do!
- self.values = {'j_username': self.log, 'j_password': self.pas} # And $POST parameters too, Isn't it cool?
- self.data = urllib.urlencode(self.values) # Of course it can encode $POST too
- self.req = urllib2.Request('https://dv.b2blk.megafon.ru/sc_cp_apps/loginProcess', self.data, self.headers)# And compile all theese cool small things in one request, yay!
- self.response = urllib2.urlopen(self.req) # 0pen this request
- self.updater() # And process it by his own methods
- self.root.mainloop()
- def updater(self):
- self.response = urllib2.urlopen(self.req)
- self.response = urllib2.urlopen('https://dv.b2blk.megafon.ru/sc_cp_apps/account/accountInfo/19435519')
- site1 = self.response.read()
- site_u = lxml.html.document_fromstring(site1)
- balance = site_u.xpath('//span[@class="money bold"]/text()')
- self.var.set(u'Баланс аккаунта: '+balance[0])
- self.label.pack()
- self.root.update_idletasks()
- self.root.after(1000, self.updater)
- app = App()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement