예제 #1
0
'''
@File    :   双色球.py
@Time    :   2020/01/10 08:36:49
@Author  :   Kellan Fan 
@Version :   1.0
@Contact :   [email protected]
@Desc    :   None
'''

# here put the import lib
from lxml import etree
from misc.openurl import OpenUrl
from misc.pg_client import Mypostgres
from log.create_logger import create_logger

logger = create_logger()

url = 'http://www.310win.com/shuangseqiu/tubiao_lshm.html'
ourl = OpenUrl(url)
code, doc = ourl.run()
pg_conn = Mypostgres()
s_sql = 'select opendate from shuang_se_qiu order by opendate desc limit 1'
last_time = pg_conn.execute(s_sql)
if code == 200:
    selecter = etree.HTML(doc)
    info_list = selecter.xpath("//span[@id='spnHidValue']/text()")
    for item in info_list[0].split('#'):
        item_info = item.split('+')
        if len(item_info) > 1:
            opendate = item_info[0].split('&')[1]
            issue_num = item_info[1]
예제 #2
0
@File    :   pg_client.py
@Time    :   2019/11/03 18:13:37
@Author  :   Kellan Fan 
@Version :   1.0
@Contact :   [email protected]
@Desc    :   None
'''

# here put the import lib
import json
import etcd
import psycopg2
import sys
sys.path.append('..')
from log.create_logger import create_logger
logger = create_logger('pg_client')

class Mypostgres(object):
    def __init__(self):
        try:
            etc_client = etcd.Client(host='etcd', port=2379)
            etc_result = etc_client.read('/python/info/postgresql')
            self.postgresql_info = json.loads(etc_result.value)
        except Exception as e:
            self.postgresql_info = {}
            logger.error('Connect to Etcd server failed: [{}]'.format(e))

    def __init_conn(self):
        try:
            conn=psycopg2.connect(
                database=self.postgresql_info['database'],