Created
October 17, 2011 17:49
-
-
Save pagenoare/1293251 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import re | |
import mechanize | |
pattern = re.compile('<tr><th class="black tdl">W dniu <b>([^\<]+)</b> o godzinie <b>([^\<]+)</b> przyrost Twojego portfela wynosi</th><td class="money1">([^\%]+)%</td></tr>') | |
class SIGG(object): | |
def __init__(self): | |
self.browser = mechanize.Browser() | |
self.browser.open('https://sigg.gpw.com.pl/') | |
def login(self, login, password): | |
self.browser.select_form(name='logfrm') | |
self.browser['login'] = login | |
self.browser['password'] = password | |
self.browser.submit() | |
def get_data(self): | |
self.browser.open('https://sigg.gpw.com.pl/?task=portfolio') | |
matched = pattern.search(self.browser.response().read()) | |
return matched.group(1), matched.group(2), matched.group(3)[:-1] | |
def main(): | |
sigg = SIGG() | |
sigg.login('user', 'pass') | |
f = open('sigg/index.html', 'w') | |
date, hour, percent = sigg.get_data() | |
if percent[0] == '-': | |
f.write('<span style="font-size: 52px;">[%s %s] <span style="color: red;">%s</span></span> \n' % (date, hour, percent + '%')) | |
else: | |
f.write('<span style="font-size: 52px;">[%s %s] <span style="color: green;">%s</span></span> \n' % (date, hour, percent + '%')) | |
f.close() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment