2010年08月09日 星期一 18:46
写这个程序的想法源自现在的社会物价飞涨,工资踏步,如果再不想点办法投资理财的话,原本就可怜的薪水也要大幅贬值了。 注重投资理财的同学最近可能会发现,欧元从两三个月前的最低点812左右涨到现在900左右,如果这个机会我们能抓住的话,也可以当给自己发点奖金了。 当然,如果你整天去关注汇率的话,势必影响工作。那么有什么办法,可以在某种外币涨到某一价格(你觉得可卖)或者跌到某一价格(你觉得可买)能主动通知你,比如发个邮件通知。这个软件就是实现这个功能的。 软件功能:输入外币种类,以及高点和低点,软件每30秒(可设置)从http://www.cmbchina.com/cmbwebpu ... realtimefxrate.aspx获取当前汇率,当汇率高于高点或者低于低点时邮件通知。 软件实现: #coding:utf-8 import sys,urllib2,time import HTMLParser from smtplib import SMTP as smtp class CurrencyParser(HTMLParser.HTMLParser): selected = ('tr','td') def reset(self): HTMLParser.HTMLParser.reset(self) self._level_stack = [] self._htmldata = [] def handle_starttag(self, tag, attrs): if tag in CurrencyParser.selected: self._level_stack.append(tag) def handle_endtag(self, tag): if self._level_stack \ and tag in CurrencyParser.selected \ and tag == self._level_stack[-1]: self._level_stack.pop() def handle_data(self, data): if "/".join(self._level_stack) in ('tr/td/tr/td/tr/td',): self._htmldata.append(data) def sendmail(): s = smtp('smtp.126.com') s.login('你的邮箱名','你的邮箱密码') s.sendmail('name1在126.com','name2在126.com','From:master\r\nTo:user\r\nSubject: Deal\r\n\r\nDeal\r\n') if __name__ == '__main__': currency = (u'港币',u'澳大利亚元',u'美元',u'欧元',u'加拿大元',u'英镑',u'日元',u'新加坡元',u'瑞士法郎') rate = {} for i in range(len(currency)): rate[currency] = [0,0,0,0] select_currency = raw_input('请输入外汇名称: ') value_high = float(raw_input('请输入高点: ')) value_low = float(raw_input('请输入低点: ')) select_currency_unicode = select_currency.decode('utf-8') while True: req = urllib2.Request('http://www.cmbchina.com/cmbwebpubinfo/fxrealrate/realtimefxrate.aspx') fd = urllib2.urlopen(req) data = fd.read() parser = CurrencyParser() parser.feed(data) for i in range(len(parser._htmldata)): for j in range(len(currency)): if parser._htmldata.decode('gb2312') == currency[j]: rate[currency[j]] = [parser._htmldata[i+3],parser._htmldata[i+4],parser._htmldata[i+5],parser._htmldata[i+6]] for j in range(len(currency)): if select_currency_unicode == currency[j]: print currency[j].encode('utf-8'), rate[currency[j]] if float(rate[currency[j]][0]) > value_high: #sendmail() value_high += 1 elif float(rate[currency[j]][0]) < value_low: #sendmail() value_low -=1 parser.close() time.sleep(30) 示例: chenkang:~/python#python cmb.py 请输入外汇名称: 欧元 请输入高点: 999 请输入低点: 888 欧元 ['898.66', '902.25', '895.07', '866.76'] 欧元 ['898.59', '902.18', '895.00', '866.69'] 欧元 ['898.59', '902.18', '895.00', '866.69'] 欧元 ['898.59', '902.18', '895.00', '866.69'] 欧元 ['898.66', '902.25', '895.07', '866.76'] 欧元 ['898.70', '902.29', '895.11', '866.80'] 欧元 ['898.84', '902.44', '895.24', '866.93'] 欧元 ['898.84', '902.44', '895.24', '866.93'] 欧元 ['898.84', '902.44', '895.24', '866.93'] 欧元 ['898.84', '902.44', '895.24', '866.93'] 欧元 ['898.84', '902.44', '895.24', '866.93'] 欧元 ['898.90', '902.50', '895.30', '866.99'] 欧元 ['898.77', '902.37', '895.17', '866.86'] 欧元 ['898.77', '902.37', '895.17', '866.86'] 欧元 ['898.84', '902.44', '895.24', '866.93']
2010年08月10日 星期二 21:54
有意思,:) Kang Chen 写道: > 写这个程序的想法源自现在的社会物价飞涨,工资踏步,如果再不想点办法投资理财的话,原本就可怜的薪水也要大幅贬值了。 > 注重投资理财的同学最近可能会发现,欧元从两三个月前的最低点812左右涨到现在900左右,如果这个机会我们能抓住的话,也可以当给自己发点奖金了。 > 当然,如果你整天去关注汇率的话,势必影响工作。那么有什么办法,可以在某种外币涨到某一价格(你觉得可卖)或者跌到某一价格(你觉得可买)能主动通知你,比如发个邮件通知。这个软件就是实现这个功能的。 > 软件功能:输入外币种类,以及高点和低点,软件每30秒(可设置)从http://www.cmbchina.com/cmbwebpu ... realtimefxrate.aspx获取当前汇率,当汇率高于高点或者低于低点时邮件通知。 > 软件实现: > #coding:utf-8 > import sys,urllib2,time > import HTMLParser > from smtplib import SMTP as smtp > > class CurrencyParser(HTMLParser.HTMLParser): > selected = ('tr','td') > > def reset(self): > HTMLParser.HTMLParser.reset(self) > self._level_stack = [] > self._htmldata = [] > def handle_starttag(self, tag, attrs): > if tag in CurrencyParser.selected: > self._level_stack.append(tag) > def handle_endtag(self, tag): > if self._level_stack \ > and tag in CurrencyParser.selected \ > and tag == self._level_stack[-1]: > self._level_stack.pop() > def handle_data(self, data): > if "/".join(self._level_stack) in ('tr/td/tr/td/tr/td',): > self._htmldata.append(data) > > def sendmail(): > s = smtp('smtp.126.com') > s.login('你的邮箱名','你的邮箱密码') > s.sendmail('name1 at 126.com','name2 at 126.com','From:master\r\nTo:user\r\nSubject: Deal\r\n\r\nDeal\r\n') > > > if __name__ == '__main__': > currency = (u'港币',u'澳大利亚元',u'美元',u'欧元',u'加拿大元',u'英镑',u'日元',u'新加坡元',u'瑞士法郎') > rate = {} > for i in range(len(currency)): > rate[currency] = [0,0,0,0] > select_currency = raw_input('请输入外汇名称: ') > value_high = float(raw_input('请输入高点: ')) > value_low = float(raw_input('请输入低点: ')) > select_currency_unicode = select_currency.decode('utf-8') > while True: > req = urllib2.Request('http://www.cmbchina.com/cmbwebpubinfo/fxrealrate/realtimefxrate.aspx') > fd = urllib2.urlopen(req) > data = fd.read() > parser = CurrencyParser() > parser.feed(data) > for i in range(len(parser._htmldata)): > for j in range(len(currency)): > if parser._htmldata.decode('gb2312') == currency[j]: > rate[currency[j]] = [parser._htmldata[i+3],parser._htmldata[i+4],parser._htmldata[i+5],parser._htmldata[i+6]] > for j in range(len(currency)): > if select_currency_unicode == currency[j]: > print currency[j].encode('utf-8'), rate[currency[j]] > if float(rate[currency[j]][0]) > value_high: > #sendmail() > value_high += 1 > elif float(rate[currency[j]][0]) < value_low: > #sendmail() > value_low -=1 > parser.close() > time.sleep(30) > > 示例: > chenkang:~/python#python cmb.py > 请输入外汇名称: 欧元 > 请输入高点: 999 > 请输入低点: 888 > 欧元 ['898.66', '902.25', '895.07', '866.76'] > 欧元 ['898.59', '902.18', '895.00', '866.69'] > 欧元 ['898.59', '902.18', '895.00', '866.69'] > 欧元 ['898.59', '902.18', '895.00', '866.69'] > 欧元 ['898.66', '902.25', '895.07', '866.76'] > 欧元 ['898.70', '902.29', '895.11', '866.80'] > 欧元 ['898.84', '902.44', '895.24', '866.93'] > 欧元 ['898.84', '902.44', '895.24', '866.93'] > 欧元 ['898.84', '902.44', '895.24', '866.93'] > 欧元 ['898.84', '902.44', '895.24', '866.93'] > 欧元 ['898.84', '902.44', '895.24', '866.93'] > 欧元 ['898.90', '902.50', '895.30', '866.99'] > 欧元 ['898.77', '902.37', '895.17', '866.86'] > 欧元 ['898.77', '902.37', '895.17', '866.86'] > 欧元 ['898.84', '902.44', '895.24', '866.93'] > _______________________________________________ > zeuux-python mailing list > zeuux-python at zeuux.org > http://www.zeuux.org/mailman/listinfo/zeuux-python >
2010年08月10日 星期二 21:59
Èí¼þÿ30Ã루¿ÉÉèÖã©´Óhttp://www.cmbchina.com/cmbwebpu ... realtimefxrate.aspx»ñÈ¡µ±Ç°»ãÂÊ ÄãÊÇÕâô×öµÄtime.sleep(30)£¬Óеãå°¡¡£ ÔÚ 2010Äê8ÔÂ9ÈÕ ÏÂÎç6:46£¬Kang Chen <Kang.Chen在ecitele.com>дµÀ£º > дÕâ¸ö³ÌÐòµÄÏë·¨Ô´×ÔÏÖÔÚµÄÉç»áÎï¼Û·ÉÕÇ£¬¹¤×Ê̤²½£¬Èç¹ûÔÙ²»Ïëµã°ì·¨Í¶×ÊÀí²ÆµÄ»°£¬Ô±¾¾Í¿ÉÁ¯µÄнˮҲҪ´ó·ù±áÖµÁË¡£ > ×¢ÖØͶ×ÊÀí²ÆµÄͬѧ×î½ü¿ÉÄܻᷢÏÖ£¬Å·Ôª´ÓÁ½Èý¸öÔÂÇ°µÄ×îµÍµã812×óÓÒÕǵ½ÏÖÔÚ900×óÓÒ£¬Èç¹ûÕâ¸ö»ú»áÎÒÃÇÄÜץסµÄ»°£¬Ò²¿ÉÒÔµ±¸ø×Ô¼º·¢µã½±½ðÁË¡£ > > µ±È»£¬Èç¹ûÄãÕûÌìÈ¥¹Ø×¢»ãÂʵĻ°£¬ÊƱØÓ°Ï칤×÷¡£ÄÇôÓÐʲô°ì·¨£¬¿ÉÒÔÔÚijÖÖÍâ±ÒÕǵ½Ä³Ò»¼Û¸ñ£¨Äã¾õµÃ¿ÉÂô£©»òÕßµøµ½Ä³Ò»¼Û¸ñ£¨Äã¾õµÃ¿ÉÂò£©ÄÜÖ÷¶¯Í¨ÖªÄ㣬±ÈÈç·¢¸öÓʼþ֪ͨ¡£Õâ¸öÈí¼þ¾ÍÊÇʵÏÖÕâ¸ö¹¦Äܵġ£ > Èí¼þ¹¦ÄÜ£ºÊäÈëÍâ±ÒÖÖÀ࣬ÒÔ¼°¸ßµãºÍµÍµã£¬Èí¼þÿ30Ã루¿ÉÉèÖã©´Óhttp://www.cmbchina.com/cmbwebpu ... > realtimefxrate.aspx»ñÈ¡µ±Ç°»ãÂÊ£¬µ±»ãÂʸßÓڸߵã»òÕßµÍÓڵ͵ãʱÓʼþ֪ͨ¡£ > Èí¼þʵÏÖ: > #coding:utf-8 > import sys,urllib2,time > import HTMLParser > from smtplib import SMTP as smtp > > class CurrencyParser(HTMLParser.HTMLParser): > selected = ('tr','td') > > def reset(self): > HTMLParser.HTMLParser.reset(self) > self._level_stack = [] > self._htmldata = [] > def handle_starttag(self, tag, attrs): > if tag in CurrencyParser.selected: > self._level_stack.append(tag) > def handle_endtag(self, tag): > if self._level_stack \ > and tag in CurrencyParser.selected \ > and tag == self._level_stack[-1]: > self._level_stack.pop() > def handle_data(self, data): > if "/".join(self._level_stack) in ('tr/td/tr/td/tr/td',): > self._htmldata.append(data) > > def sendmail(): > s = smtp('smtp.126.com') > s.login('ÄãµÄÓÊÏäÃû','ÄãµÄÓÊÏäÃÜÂë') > s.sendmail('name1在126.com','name2在126.com','From:master\r\nTo:user\r\nSubject: > Deal\r\n\r\nDeal\r\n') > > > if __name__ == '__main__': > currency = > (u'¸Û±Ò',u'°Ä´óÀûÑÇÔª',u'ÃÀÔª',u'Å·Ôª',u'¼ÓÄôóÔª',u'Ó¢°÷',u'ÈÕÔª',u'мÓÆÂÔª',u'ÈðÊ¿·¨ÀÉ') > rate = {} > for i in range(len(currency)): > rate[currency] = [0,0,0,0] > select_currency = raw_input('ÇëÊäÈëÍâ»ãÃû³Æ: ') > value_high = float(raw_input('ÇëÊäÈë¸ßµã: ')) > value_low = float(raw_input('ÇëÊäÈëµÍµã: ')) > select_currency_unicode = select_currency.decode('utf-8') > while True: > req = urllib2.Request(' > http://www.cmbchina.com/cmbwebpubinfo/fxrealrate/realtimefxrate.aspx') > fd = urllib2.urlopen(req) > data = fd.read() > parser = CurrencyParser() > parser.feed(data) > for i in range(len(parser._htmldata)): > for j in range(len(currency)): > if parser._htmldata.decode('gb2312') == > currency[j]: > rate[currency[j]] = > [parser._htmldata[i+3],parser._htmldata[i+4],parser._htmldata[i+5],parser._htmldata[i+6]] > for j in range(len(currency)): > if select_currency_unicode == currency[j]: > print currency[j].encode('utf-8'), > rate[currency[j]] > if float(rate[currency[j]][0]) > value_high: > #sendmail() > value_high += 1 > elif float(rate[currency[j]][0]) < > value_low: > #sendmail() > value_low -=1 > parser.close() > time.sleep(30) > > ʾÀý£º > chenkang:~/python#python cmb.py > ÇëÊäÈëÍâ»ãÃû³Æ: Å·Ôª > ÇëÊäÈë¸ßµã: 999 > ÇëÊäÈëµÍµã: 888 > ŷԪ ['898.66', '902.25', '895.07', '866.76'] > ŷԪ ['898.59', '902.18', '895.00', '866.69'] > ŷԪ ['898.59', '902.18', '895.00', '866.69'] > ŷԪ ['898.59', '902.18', '895.00', '866.69'] > ŷԪ ['898.66', '902.25', '895.07', '866.76'] > ŷԪ ['898.70', '902.29', '895.11', '866.80'] > ŷԪ ['898.84', '902.44', '895.24', '866.93'] > ŷԪ ['898.84', '902.44', '895.24', '866.93'] > ŷԪ ['898.84', '902.44', '895.24', '866.93'] > ŷԪ ['898.84', '902.44', '895.24', '866.93'] > ŷԪ ['898.84', '902.44', '895.24', '866.93'] > ŷԪ ['898.90', '902.50', '895.30', '866.99'] > ŷԪ ['898.77', '902.37', '895.17', '866.86'] > ŷԪ ['898.77', '902.37', '895.17', '866.86'] > ŷԪ ['898.84', '902.44', '895.24', '866.93'] > _______________________________________________ > zeuux-python mailing list > zeuux-python在zeuux.org > http://www.zeuux.org/mailman/listinfo/zeuux-python > -------------- ÏÂÒ»²¿·Ö -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: <http://www.zeuux.org/pipermail/zeuux-python/attachments/20100810/02e16f76/attachment.html>
Zeuux © 2024
京ICP备05028076号