Example #1
0
def GetLottoHistoryToSQL(soup):
    lastSeries = getLastSeries(soup)
    chkQuery = "SELECT series from lotto_history"
    chkResult = sql.selectStmt(chkQuery)
    chkList = []
    for row in chkResult:
        chkList.append(int(row[0]))
    crawlingList = list(set(list(range(1, lastSeries+1))) - set(chkList))

    if crawlingList.__len__() == 0:
        print('대상 없음')
        return

    for i in crawlingList:
        url = 'http://www.nlotto.co.kr/gameResult.do?method=byWin&drwNo=' + str(i)

        soup = BeautifulSoup(urllib.request.urlopen(url).read(), "lxml")

        result = str(soup.find(id="desc")['content'])
        ret = result.split('당첨번호')

        nubmerList = ret[1].split('.')[0].strip().split('+')[0].split((','))
        n1, n2, n3, n4, n5, n6 = nubmerList
        bonusNumber = ret[1].split('.')[0].strip().split('+')[1]
        totalCnt = ret[1].split('.')[1].split(('총'))[1].split(',')[0].strip().replace('명','').replace(',', '')
        price = ret[1].split('.')[1].split(('총'))[1].split('당첨금액')[1].strip().replace('원','').replace(',', '')

        print(str(i) + '회 당첨번호 :', nubmerList, '보너스 번호 :', bonusNumber, '1등 수 :', totalCnt, '인당 당첨금액 :', price)
        query = "insert into lotto_history(series, n1, n2, n3, n4, n5, n6, bonus_n, total_winner, each_price, timestamp) VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, NOW()) " % (int(i), int(n1), int(n2), int(n3), int(n4), int(n5), int(n6), int(bonusNumber), int(totalCnt), int(price))
        sql.insertStmt(query=query)

# GetLottoHistoryToSQL(soup)
 def __init__(self, connectArgs):        
     verbose, cacheUser, connectParams= self.__unpackConnectArgs(connectArgs)
     self.verbose=verbose
     if cacheUser:
         import MySQL
         self.conn=MySQL.getConnection(cacheUser)
     else:
         self.conn=MySQLdb.connect(**connectParams)
     self.bindVariables = 0
Example #3
0
    def __init__(self, parent, title, nlist, user):
        self.user = user
        if nlist == 3:
            self.nsize = nlist
            wx.Frame.__init__(self, parent, title=title, size=(600, 600))
            self.font1 = wx.Font(20, wx.MODERN, wx.NORMAL, wx.NORMAL, False,
                                 'Consolas')
            panel = wx.Panel(self, -1)  # 布局
            # self.control = wx.TextCtrl(panel, pos =(20,20), size=(50,50),style = wx.TE_CENTER)  # 控制TextCtrl
            self.list_text_id = list()
            list_tmp_num = self.Num(3)
            rnum = random.randint(3, 5)
            # print(rnum)
            cntnum = 0
            stmp = 0
            for i in range(0, 3):  #  0 1 2
                for j in range(0, 3):  # 0 1 2
                    s = random.randint(stmp, 5)
                    if s > 2 and rnum > 0:
                        stmp = 0
                        rnum -= 1
                        text = wx.TextCtrl(panel,
                                           wx.ID_ANY,
                                           pos=(90 + i * 120, 50 + j * 120),
                                           size=(50, 50),
                                           style=wx.TE_READONLY | wx.TE_CENTER)
                        text.SetValue(str(list_tmp_num[int(i * 3 + j)]))
                        text.SetFont(self.font1)
                        text.SetMaxLength(1)
                        self.list_text_id.append(text.GetId())
                    else:
                        stmp += 1
                        text = wx.TextCtrl(panel,
                                           wx.ID_ANY,
                                           pos=(90 + i * 120, 50 + j * 120),
                                           size=(50, 50),
                                           style=wx.TE_CENTER)
                        text.SetFont(self.font1)
                        text.SetMaxLength(1)
                        self.list_text_id.append(text.GetId())
                    self.row.append(text.GetId())
                self.row_list.append(self.row)
        elif nlist == 9:
            self.nsize = nlist
            wx.Frame.__init__(self, parent, title=title, size=(1000, 700))
            self.font1 = wx.Font(20, wx.MODERN, wx.NORMAL, wx.NORMAL, False,
                                 'Consolas')
            panel = wx.Panel(self, -1)
            self.list_text_id = list()
            list_tmp_num = self.Num(9)
            rnum = random.randint(20, 60)
            cntnum = 0
            stmp = 0
            for i in range(0, 9):
                for j in range(0, 9):
                    s = random.randint(stmp, stmp + 3)
                    if s > 2 and rnum > 0:
                        stmp = 0
                        rnum -= 1
                        text = wx.TextCtrl(panel,
                                           wx.ID_ANY,
                                           pos=(30 + i * 50, 30 + j * 50),
                                           size=(50, 50),
                                           style=wx.TE_READONLY | wx.TE_CENTER)
                        text.SetValue(str(list_tmp_num[i][j]))
                        text.SetFont(self.font1)
                        text.SetMaxLength(1)
                        self.list_text_id.append(text.GetId())
                    else:
                        stmp += 1
                        text = wx.TextCtrl(panel,
                                           wx.ID_ANY,
                                           pos=(30 + i * 50, 30 + j * 50),
                                           size=(50, 50),
                                           style=wx.TE_CENTER)
                        text.SetFont(self.font1)
                        text.SetMaxLength(1)
                        self.list_text_id.append(text.GetId())
                    self.row.append(text.GetId())
                self.row_list.append(self.row)
        else:
            self.nsize = nlist
            wx.Frame.__init__(self, parent, title=title, size=(1000, 700))
            self.font1 = wx.Font(20, wx.MODERN, wx.NORMAL, wx.NORMAL, False,
                                 'Consolas')
            panel = wx.Panel(self, -1)  # 布局
            self.list_text_id = list()
            list_tmp_num = self.Num(9)
            rnum = random.randint(20, 60)
            mysql = MySQL.mysql()
            sql = "select * from userplay where usera = '" + self.user + "' or userb = '" + self.user + "'"
            res = mysql.newselect(sql)
            touser = 0
            if res[0][0] == self.user:
                touser = res[0][1]
                addr = res[0][3]
                self.toip = res[0][4]
            else:
                touser = res[0][0]
                addr = res[0][4]
                self.toip = res[0][3]
            # self.toip='192.168.43.213'
            self.myip = addr
            s = MySQL.mysql()
            print('self.toip::' + self.toip)
            wx.StaticText(panel, label='名称', pos=(700, 0)).SetFont(self.font1)
            sql = "select uname from user where uid = '" + user + "'"
            wx.StaticText(panel, label=s.newselect(sql)[0][0],
                          pos=(800, 0)).SetFont(self.font1)
            wx.StaticText(panel, label='分数', pos=(700, 30)).SetFont(self.font1)
            sql = "select rankcnt from user where uid = '" + user + "'"
            wx.StaticText(panel, label=s.newselect(sql)[0][0],
                          pos=(800, 30)).SetFont(self.font1)
            wx.StaticText(panel, label='段位', pos=(700, 60)).SetFont(self.font1)
            sql = "select rankValue from user,user_rank where user.uid = '" + self.user + "' and user.rankID = user_rank.rankID"
            wx.StaticText(panel, label=s.newselect(sql)[0][0],
                          pos=(800, 60)).SetFont(self.font1)
            self.thread_rev = Thread(target=self.Tcp_Rev, args=(self.toip, ))
            self.thread_rev.start()
            self.mycnt = wx.TextCtrl(panel,
                                     wx.ID_ANY,
                                     pos=(700, 100),
                                     size=(50, 50),
                                     style=wx.TE_READONLY | wx.TE_CENTER)
            self.mycnt.SetValue('0')
            self.mycnt.SetFont(self.font1)
            self.tocnt = wx.TextCtrl(panel,
                                     wx.ID_ANY,
                                     pos=(700, 300),
                                     size=(50, 50),
                                     style=wx.TE_READONLY | wx.TE_CENTER)
            self.tocnt.SetValue('0')
            self.tocnt.SetFont(self.font1)
            wx.StaticText(panel, label='名称',
                          pos=(700, 200)).SetFont(self.font1)
            sql = "select uname from user where uid = '" + touser + "'"
            wx.StaticText(panel, label=s.newselect(sql)[0][0],
                          pos=(800, 200)).SetFont(self.font1)
            wx.StaticText(panel, label='分数',
                          pos=(700, 230)).SetFont(self.font1)
            sql = "select rankcnt from user where uid = '" + touser + "'"
            wx.StaticText(panel, label=s.newselect(sql)[0][0],
                          pos=(800, 230)).SetFont(self.font1)
            wx.StaticText(panel, label='段位',
                          pos=(700, 260)).SetFont(self.font1)
            sql = "select rankValue from user,user_rank where user.uid = '" + touser + "' and user.rankID = user_rank.rankID"
            wx.StaticText(panel, label=s.newselect(sql)[0][0],
                          pos=(800, 260)).SetFont(self.font1)
            cntnum = 0
            stmp = 0
            for i in range(0, 9):  #  0 1 2
                for j in range(0, 9):  # 0 1 2
                    s = random.randint(stmp, stmp + 3)
                    if s > 2 and rnum > 0:
                        stmp = 0
                        rnum -= 1
                        text = wx.TextCtrl(panel,
                                           wx.ID_ANY,
                                           pos=(30 + i * 50, 30 + j * 50),
                                           size=(50, 50),
                                           style=wx.TE_READONLY | wx.TE_CENTER)
                        text.SetValue(str(list_tmp_num[i][j]))
                        text.SetFont(self.font1)
                        text.SetMaxLength(1)
                        self.list_text_id.append(text.GetId())
                    else:
                        stmp += 1
                        text = wx.TextCtrl(panel,
                                           wx.ID_ANY,
                                           pos=(30 + i * 50, 30 + j * 50),
                                           size=(50, 50),
                                           style=wx.TE_CENTER)
                        text.SetFont(self.font1)
                        text.SetMaxLength(1)
                        self.list_text_id.append(text.GetId())
                    self.row.append(text.GetId())
                self.row_list.append(self.row)
        self.Center()
        filemenu = wx.Menu()

        menuAbout = filemenu.Append(wx.ID_ABOUT, "About",
                                    " Information about this program")
        filemenu.AppendSeparator()
        menuExit = filemenu.Append(wx.ID_EXIT, "Exit",
                                   " Terminate the program")

        menuBar = wx.MenuBar()
        menuBar.Append(filemenu, "File")
        self.SetMenuBar(menuBar)

        self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
        self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
        for i in self.list_text_id:
            objControl = self.FindWindowById(i)
            self.Bind(wx.EVT_TEXT, self.listennum, objControl)

        self.Show(True)
from SkunkWeb import Configuration
import MySQL
from SkunkExcept import SkunkStandardError
from requestHandler.requestHandler import CleanupRequest

Configuration.mergeDefaults(
    MySQLConnectParams = {},
    MySQLRollback=0,
    MySQLTestFunc=None
    )

# add test function (used by MySQL connection cache to test
# connections before handing them out)
MySQL.connection_test=Configuration.MySQLTestFunc

for u, p in Configuration.MySQLConnectParams.items():
    MySQL.initUser(u, p)

# optional rollback
def rollback(*args):
    for v in MySQL._connections.values():
        try:
            v.rollback()
        except:
            pass
        
if Configuration.MySQLRollback:
    CleanupRequest.addFunction(rollback)

#   s q l P h o n e . p y
#
#    Maintain mysql database table 'phones'
#
from Tkinter import *
import MySQL

db = MySQL.connect("")
db.selectdb("test")


def whichSelected():
    print "At %s" % (select.curselection())
    return int(select.curselection()[0])


def dosql(cmd):
    print cmd
    c = db.query(cmd)
    setSelect()


def addEntry():
    c = db.query("select max(id)+1 from phones")
    id = c.fetchdict()[0].values()[0]  # digs deep to get next id
    dosql("insert into phones values (%d,'%s','%s')" % (id, nameVar.get(), phoneVar.get()))


def updateEntry():
    id = phoneList[whichSelected()][0]
    dosql("update phones set name='%s', phone='%s' where id=%d" % (nameVar.get(), phoneVar.get(), id))
Example #6
0
def saveIntoMySQL(fname, db=None):
    db = MySQL.MySQL(
        host="localhost", usr="******", passwd="root",
        dbase='bug320') if db == None else db
    links = openCSV(fname)
    for link in links:
        #if True:
        #link = links[0]
        save = True
        html = download(link[1], headers)
        if html == None:
            save = False
        soup = BeautifulSoup(html, htmlparser)
        if soup == None:
            save = False
        if save == False:
            db.insert("subpage", title="", url=link[1], flag=str(save))
        else:
            attr = []  # title=0,gongsi=1,person=2,time=3,
            #print soup.prettify()
            attr.append(
                soup.find("h1",
                          attrs={
                              "class":
                              "TxtCenter Padding10 BorderEEEBottom Top5"
                          }).string.encode("utf-8"))  #class="TxtCenters
            #attr.append(string.string for string in soup.find_all("span",attrs={"class":"Blue"}))
            for string in soup.find_all("span", attrs={"class": "Blue"}):
                attr.append(string.string.encode("utf-8"))
                pass
            #for at in attr:
            #    print at
            sql = "url = '%s'" % (link[1])
            sql = "select title from subpage where %s" % sql
            if not db.selectSQL("subpage", sql):
                #print bool(db.selectSQL("subpage",sql))
                #db.execSQL("subpage","set names utf8")
                db.insert("subpage",
                          url=link[1],
                          title=attr[0],
                          gongsi=attr[1],
                          person=attr[2],
                          time=attr[3],
                          user=attr[4],
                          flag=str(save))
            else:
                ##print  "OK"
                sql = "url = '%s'" % (link[1])
                sql = "select flag from subpage where %s" % sql
                #sql = "url = '%s'" % (link[1])
                if bool(db.selectSQL("subpage", sql)[0]['flag']) == False:
                    sql = "url = '%s'" % (link[1])
                    # title = attr[0], gongsi = attr[1], person = attr[2], time = attr[3], user = attr[4], flag = str(save)
                    db.update(title=attr[0],
                              gongsi=attr[1],
                              person=attr[2],
                              time=attr[3],
                              user=attr[4],
                              flag=str(save),
                              where=sql)
                else:
                    print "Ok"
            """
            <div class="BorderEEE BorderRedTop" style="min-height:400px;">
            <h1 class="TxtCenter Padding10 BorderEEEBottom Top5">
            关于洛阳市公安局办案设备采购项目的中标结果公告
            </h1>
            <div class="TxtRight Padding5">
            发布机构:
            <span class="Blue">
            洛阳泽丰建设工程咨询有限公司
            </span>
            发布人:
            <span class="Blue">
            张晓燕
            </span>
            发布日期:
            <span class="Blue">
            2017-06-14 08:53
            </span>
            访问次数:
            <span class="Blue">
            27
            </span>
            </div>
            """
            pass

    pass
Example #7
0
def getKbds():
    return {
        "Principal":
        [[
            InlineKeyboardButton(MySQL.getTranslation(db_connection, 'tmp',
                                                      lang),
                                 callback_data='Temperatura'),
            InlineKeyboardButton(MySQL.getTranslation(db_connection, 'hum',
                                                      lang),
                                 callback_data='Humedad')
        ],
         [
             InlineKeyboardButton(MySQL.getTranslation(db_connection, 'lig',
                                                       lang),
                                  callback_data='Luz'),
             InlineKeyboardButton(MySQL.getTranslation(db_connection, 'prs',
                                                       lang),
                                  callback_data='Presion')
         ]],
        "Temperatura":
        [[
            InlineKeyboardButton(MySQL.getTranslation(db_connection, 'max_tmp',
                                                      lang),
                                 callback_data='TMax'),
            InlineKeyboardButton(MySQL.getTranslation(db_connection, 'min_tmp',
                                                      lang),
                                 callback_data='TMin')
        ],
         [
             InlineKeyboardButton(MySQL.getTranslation(db_connection,
                                                       'avg_tmp', lang),
                                  callback_data='TMedia'),
             InlineKeyboardButton(MySQL.getTranslation(db_connection,
                                                       'cur_tmp', lang),
                                  callback_data='TActual')
         ],
         [
             InlineKeyboardButton(MySQL.getTranslation(db_connection, 'back',
                                                       lang),
                                  callback_data='@back')
         ]],
        "Humedad":
        [[
            InlineKeyboardButton(MySQL.getTranslation(db_connection, 'max_hum',
                                                      lang),
                                 callback_data='HMax'),
            InlineKeyboardButton(MySQL.getTranslation(db_connection, 'min_hum',
                                                      lang),
                                 callback_data='HMin')
        ],
         [
             InlineKeyboardButton(MySQL.getTranslation(db_connection,
                                                       'avg_hum', lang),
                                  callback_data='HMedia'),
             InlineKeyboardButton(MySQL.getTranslation(db_connection,
                                                       'cur_hum', lang),
                                  callback_data='HActual')
         ],
         [
             InlineKeyboardButton(MySQL.getTranslation(db_connection, 'back',
                                                       lang),
                                  callback_data='@back')
         ]],
        "Luz":
        [[
            InlineKeyboardButton(MySQL.getTranslation(db_connection, 'max_lig',
                                                      lang),
                                 callback_data='LMax'),
            InlineKeyboardButton(MySQL.getTranslation(db_connection, 'min_lig',
                                                      lang),
                                 callback_data='LMin')
        ],
         [
             InlineKeyboardButton(MySQL.getTranslation(db_connection,
                                                       'avg_lig', lang),
                                  callback_data='LMedia'),
             InlineKeyboardButton(MySQL.getTranslation(db_connection,
                                                       'cur_lig', lang),
                                  callback_data='LActual')
         ],
         [
             InlineKeyboardButton(MySQL.getTranslation(db_connection, 'back',
                                                       lang),
                                  callback_data='@back')
         ]],
        "Presion": [[
            InlineKeyboardButton(MySQL.getTranslation(db_connection, 'max_prs',
                                                      lang),
                                 callback_data='PMax'),
            InlineKeyboardButton(MySQL.getTranslation(db_connection, 'min_prs',
                                                      lang),
                                 callback_data='PMin')
        ],
                    [
                        InlineKeyboardButton(MySQL.getTranslation(
                            db_connection, 'avg_prs', lang),
                                             callback_data='PMedia'),
                        InlineKeyboardButton(MySQL.getTranslation(
                            db_connection, 'cur_prs', lang),
                                             callback_data='PActual')
                    ],
                    [
                        InlineKeyboardButton(MySQL.getTranslation(
                            db_connection, 'back', lang),
                                             callback_data='@back')
                    ]],
    }
Example #8
0
def opt(bot, update):
    reply_markup = InlineKeyboardMarkup(getKbds()["Principal"])
    update.message.reply_text(MySQL.getTranslation(db_connection, 'main_menu',
                                                   lang),
                              reply_markup=reply_markup)
#  
#  Copyright (C) 2001 Andrew T. Csillag <*****@*****.**>
#  
#      This program is free software; you can redistribute it and/or modify
#      it under the terms of the GNU General Public License as published by
#      the Free Software Foundation; either version 2 of the License, or
#      (at your option) any later version.
#  
#      This program is distributed in the hope that it will be useful,
#      but WITHOUT ANY WARRANTY; without even the implied warranty of
#      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#      GNU General Public License for more details.
#  
#      You should have received a copy of the GNU General Public License
#      along with this program; if not, write to the Free Software
#      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
#   
from SkunkWeb import Configuration
import MySQL

Configuration.mergeDefaults(
    MySQLConnectParams = {},
    )

for u, p in Configuration.MySQLConnectParams.items():
    MySQL.initUser ( u, p )

Example #10
0
	def TimeFactor(self):
		lists=[]
		if self.dbconfig['party']==1:
			kaijiang_ssc=int(self.GetSsc())
		else:
			kaijiang_ssc=0
		db = MySQL(self.dbconfig)
		db.query('select kaijiang_count,kaijiang_ssc,number,id,kaijang_time,sid,no from '+self.dbconfig['prefix']+'shop_period where state=1')
		result = db.fetchAllRows()
		if result:
			for row in result:
				kaijang_num = (row[0]+row[1])%row[2]+10000001
				db.query('select uid from '+self.dbconfig['prefix']+'shop_record where pid=%d and FIND_IN_SET("%d",num)' % (row[3],kaijang_num))
				uid = db.fetchOneRow()
				if uid:
					db.update('update '+self.dbconfig['prefix']+'shop_period set kaijang_num="%s",uid=%d,state=2,kaijiang_ssc=%s where id=%d' % (kaijang_num,uid[0],kaijiang_ssc,row[3]))
					db.query('select nickname,openid from '+self.dbconfig['prefix']+'user where id=%d and status=1' % uid[0])
					user = db.fetchOneRow()
					if(user[1]):
						lists.append({"touser":user[1],"pid":row[3],"username":user[0],"no":row[6],"time":row[4],"sid":row[5]})
		db.close()
Example #11
0
#   s q l P h o n e . p y
#
#    Maintain mysql database table 'phones'
#
from Tkinter import *
import MySQL
db = MySQL.connect('')
db.selectdb("test")


def whichSelected():
    print "At %s" % (select.curselection())
    return int(select.curselection()[0])


def dosql(cmd):
    print cmd
    c = db.query(cmd)
    setSelect()


def addEntry():
    c = db.query("select max(id)+1 from phones")
    id = c.fetchdict()[0].values()[0]  # digs deep to get next id
    dosql("insert into phones values (%d,'%s','%s')" %
          (id, nameVar.get(), phoneVar.get()))


def updateEntry():
    id = phoneList[whichSelected()][0]
    dosql("update phones set name='%s', phone='%s' where id=%d" %
Example #12
0
from DHT import DHT
from Sensors import Sensors
from File import File
from MySQL import *
from MongoDB import *
import sys

newSQL = MySQL()
newMongo = MongoDB()
newSQL.Conexion()
newMongo.mongoConexion()

sensors = Sensors()
sensorList = sensors.getAllInstance()
print(sensorList)
sensorList.returnData()
Example #13
0
def main():
    db = MySQL.connectDatabase()
    MySQL.createTable(db)
 def getConnection(self):
     return MySQL.getConnection(Configuration.SessionHandler_MySQLAlias)
Example #15
0
 def Sucessjudge(self, n):
     self.ans.clear()
     if n == 3:
         for i in self.list_text_id:
             objControl = self.FindWindowById(i)
             if objControl.GetValue() != '':
                 self.ans.add(objControl.GetValue())
         if len(self.ans) == n * n:
             print('Sucess')
             dlg = wx.MessageDialog(self, "Sucess")
             dlg.ShowModal()
             dlg.Destroy()
     else:
         cnt_cur = 0
         cnt_row = 0
         ans_tmp = set()
         text_numcur = list()
         text_numrow = list()
         for i in self.list_text_id:
             objControl = self.FindWindowById(i)
             if objControl.GetValue() == '':
                 return
         for i in self.list_text_id:
             cnt_cur += 1
             objControl = self.FindWindowById(i)
             text_numcur.append(objControl.GetValue())
             ans_tmp.add(objControl.GetValue())
             if cnt_cur == 9:
                 cnt_cur = 0
                 if len(ans_tmp) != 9:
                     return
                 text_numrow.append(text_numcur)
                 text_numcur.clear()
         for i in text_numrow:
             for j in range(0, 9):
                 self.ans.add(i[j])
             if len(self.ans) != 9:
                 self.ans.clear()
                 return
         cnt_cur = 0
         cnt_row = 0
         self.ans.clear()
         set1 = set()
         set2 = set()
         set3 = set()
         for i in text_numrow:
             cnt_row += 1
             for j in i:
                 if cnt_cur % 3 == 0:
                     set1.add(j)
                 elif cnt_cur % 3 == 1:
                     set2.add(j)
                 elif cnt_cur % 3 == 2:
                     set3.add(j)
                 cnt_cur += 1
         if cnt_row == 3:
             cnt_row = 0
             if len(set1) != 9 or len(set2) != 9 or len(set3) != 9:
                 return
             set1.clear()
             set2.clear()
             set3.clear()
         print('Sucess')
         if nlist == 90:
             server.Tcp_Send('close', self.toip)
             mysql = MySQL.mysql()
             sql = "update user set rankcnt = rankcnt+100 where uid = ' " + self.user + "'"
             mysql.newupdate(sql)
         dlg = wx.MessageDialog(self, "Sucess")
         dlg.ShowModal()
         dlg.Destroy()
Example #16
0
import requests
import re
import TravelVars as tv
import json
import Creds
import SkyScannerAPI
import MySQL

# make_all_combo_sessions()
# for key in keys:
#     poll_session(key)
#
# for price in prices:
#     print(price)

MySQL.my_cursor.execute("SELECT id FROM inq_req")
db_id = MySQL.my_cursor.fetchone()
while db_id:
    id = db_id[0]
    travel_vars = MySQL.get_skyscanner_search_vars(id)
    best_price = SkyScannerAPI.get_best_price(travel_vars)
    print(best_price)
    db_id = MySQL.my_cursor.fetchone()
Example #17
0
logger = logging.getLogger(__name__)

#Telegram Bot Code
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler

import MySQL

from time import time
# Use this instead of print so that the output can be seen in a server environment
from Utils import sprint

#Commands

lang = "EN"
db_connection = MySQL.getConnection('root', 'root', 'Atmos')

txtIds = []


def getKbds():
    return {
        "Principal":
        [[
            InlineKeyboardButton(MySQL.getTranslation(db_connection, 'tmp',
                                                      lang),
                                 callback_data='Temperatura'),
            InlineKeyboardButton(MySQL.getTranslation(db_connection, 'hum',
                                                      lang),
                                 callback_data='Humedad')
        ],
Example #18
0
    def get_court_data(self):
        url = 'http://www.gpai.net/sf/courtList.do'
        html = UrlUtil.get_html(url)
        court_data_list = re.findall(
            re.compile(
                r'<a href="\S*?court.do\?id=(\d+)" target="_blank">(\S*?)</a>\s*<span class="iconfont-sf">\((\d+)',
                re.S), html.decode('utf-8'))
        return court_data_list

    def spider_and_upsert_court_info(self):
        print("start to get court list and insert into DB")
        court_info_list = self.get_court_data()
        for court_info in court_info_list:
            if court_info.__len__() > 1:
                court_id = court_info[0]
                court_name = court_info[1]
                auction_count = court_info[2]
                select_sql = 'select count(*) from Courts where CourtId=' + court_id
                insert_sql = 'insert into Courts (CourtId, CourtName, AuctionCount) values (' + court_id + ',"' + court_name + '",' + auction_count + ')'
                update_sql = 'update Courts set AuctionCount= ' + auction_count + ' where CourtId=' + court_id
                mysql.upsert(select_sql, insert_sql, update_sql)
        print("end to get court list and insert into DB")


if __name__ == '__main__':
    mysql = MySQL.MySQL()
    court_util = CourtUtil()
    court_util.spider_and_upsert_court_info()
    court_list = mysql.get_courts()
    print(court_list)
Example #19
0
def updatemenu(bot, update, query, msgId, kbdId):
    try:
        reply_markup = InlineKeyboardMarkup(getKbds()[kbdId])

        localized_manu_name = "ERROR"
        if kbdId == 'Principal':
            localized_manu_name = MySQL.getTranslation(db_connection,
                                                       'main_menu', lang)
        elif kbdId == 'Temperatura':
            localized_manu_name = MySQL.getTranslation(db_connection,
                                                       'tmp_menu', lang)
        elif kbdId == 'Humedad':
            localized_manu_name = MySQL.getTranslation(db_connection,
                                                       'hum_menu', lang)
        elif kbdId == 'Presion':
            localized_manu_name = MySQL.getTranslation(db_connection,
                                                       'prs_menu', lang)
        elif kbdId == 'Luz':
            localized_manu_name = MySQL.getTranslation(db_connection,
                                                       'lig_menu', lang)
        bot.edit_message_text(text=localized_manu_name,
                              chat_id=query.message.chat_id,
                              message_id=query.message.message_id,
                              reply_markup=reply_markup)
    except KeyError:
        if not kbdId == '@back':
            lastLecture = None
            if kbdId.endswith('Actual'):
                lastLecture = MySQL.getLastLecture(db_connection)
            elif kbdId.endswith('Media'):
                lastLecture = MySQL.getAvg(db_connection)
            elif kbdId.endswith('Max'):
                lastLecture = MySQL.getMax(db_connection)
            elif kbdId.endswith('Min'):
                lastLecture = MySQL.getMin(db_connection)

            temp = None
            hum = None
            lig = None
            prs = None
            #sprint(lastLecture.column_names)
            res = None
            try:
                res = lastLecture.fetchall()[0]
            except IndexError:
                res = None
            sprint(res)
            temp, hum, lig, prs = res
            temp, hum, lig, prs = str(temp / 100), str(hum / 100), str(
                lig / 100), str(prs / 100)
            # Data is stored *100

        # if len(lastLecture) > 0:
        #for tempf, humf, ligf, prsf in lastLecture:
        #    temp, hum, lig, prs = tempf, humf, ligf, prsf
        #    sprint(tempf, humf, ligf, prsf)
        #    break;
        #else:
        #    (temp, hum, lig, prs) = 'NO DATA'
        if (kbdId == '@back'):
            updatemenu(bot, update, query, msgId, "Principal")
            return
        elif (kbdId == 'TActual'):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'cur_tmp', lang) +
                ": " + temp)
            return
        elif (kbdId == 'HActual'):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'cur_hum', lang) +
                ": " + hum)
            return
        elif (kbdId == 'LActual'):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'cur_lig', lang) +
                ": " + lig)
            return
        elif (kbdId == "PActual"):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'cur_prs', lang) +
                ": " + prs)
            return
        elif (kbdId == 'TMedia'):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'avg_tmp', lang) +
                ": " + temp)
            return
        elif (kbdId == 'HMedia'):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'avg_hum', lang) +
                ": " + hum)
            return
        elif (kbdId == 'LMedia'):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'avg_lig', lang) +
                ": " + lig)
            return
        elif (kbdId == "PMedia"):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'avg_prs', lang) +
                ": " + prs)
            return
        elif (kbdId == 'TMax'):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'max_tmp', lang) +
                ": " + temp)
            return
        elif (kbdId == 'HMax'):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'max_hum', lang) +
                ": " + hum)
            return
        elif (kbdId == 'LMax'):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'max_lig', lang) +
                ": " + lig)
            return
        elif (kbdId == "PMax"):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'max_prs', lang) +
                ": " + prs)
            return
        elif (kbdId == 'TMin'):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'min_tmp', lang) +
                ": " + temp)
            return
        elif (kbdId == 'HMin'):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'min_hum', lang) +
                ": " + hum)
            return
        elif (kbdId == 'LMin'):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'min_lig', lang) +
                ": " + lig)
            return
        elif (kbdId == "PMin"):
            bot.send_message(
                chat_id=query.message.chat_id,
                text=MySQL.getTranslation(db_connection, 'min_prs', lang) +
                ": " + prs)
            return
        else:
            invalidMsg = bot.send_message(chat_id=query.message.chat_id,
                                          text=MySQL.getTranslation(
                                              db_connection, 'invalid_id',
                                              lang))
            time.sleep(3)
            bot.delete_message(chat_id=invalidMsg.chat_id,
                               message_id=invalidMsg.message_id)
    query.answer()
Example #20
0
def main():
    inputSt = input("Searching:")
    db = MySQL.connectDatabase()
    print("Keywords:%s" % (inputSt))
    words = jieba.cut(inputSt)
    orderURL(db, words)
Example #21
0
 def TimeFactor(self):
     if self.dbconfig['party'] == 1:
         kaijiang_ssc = int(self.GetSsc())
     else:
         kaijiang_ssc = 0
     db = MySQL(self.dbconfig)
     db.query(
         'select kaijiang_count,kaijiang_ssc,number,id,kaijang_time,sid,no from '
         + self.dbconfig['prefix'] + 'shop_period where state=1')
     result = db.fetchAllRows()
     if result:
         for row in result:
             kaijang_num = (row[0] + row[1]) % row[2] + 10000001
             db.query('select uid from ' + self.dbconfig['prefix'] +
                      'shop_record where pid=%d and FIND_IN_SET("%d",num)' %
                      (row[3], kaijang_num))
             uid = db.fetchOneRow()
             if uid:
                 db.update(
                     'update ' + self.dbconfig['prefix'] +
                     'shop_period set kaijang_num="%s",uid=%d,state=2,kaijiang_ssc=%s where id=%d'
                     % (kaijang_num, uid[0], kaijiang_ssc, row[3]))
     db.close()
Example #22
0
def getWid(db, keyword):
    sql = "select id from wordlist where word = " + "'" + keyword + "';"
    finalRt = MySQL.query(db, sql)
    if len(finalRt) == 0:
        return None
    return finalRt[0][0]
Example #23
0
def saveIntoDB(fname, db, hdb):
    # 存入 MySQL
    db = MySQL.MySQL(
        host="localhost", usr="******", passwd="root",
        dbase='bug320') if db == None else db
    links = openCSV(fname)
    for link in links:
        # if True:
        # link = links[0]
        save = True
        html = download(link[1], headers)
        if html == None:
            save = False
        soup = BeautifulSoup(html, htmlparser)
        if soup == None:
            save = False
        if save == False:
            db.insert("subpage", title="", url=link[1], flag=str(save))
        else:
            attr = []  # title=0,gongsi=1,person=2,time=3,
            # print soup.prettify()
            attr.append(
                soup.find("h1",
                          attrs={
                              "class":
                              "TxtCenter Padding10 BorderEEEBottom Top5"
                          }).string.encode("utf-8"))  # class="TxtCenters
            # attr.append(string.string for string in soup.find_all("span",attrs={"class":"Blue"}))
            for string in soup.find_all("span", attrs={"class": "Blue"}):
                attr.append(string.string.encode("utf-8"))
                pass
            # for at in attr:
            #    print at
            sql = "url = '%s'" % (link[1])
            sql = "select title from subpage where %s" % sql
            if not db.selectSQL("subpage", sql):
                # print bool(db.selectSQL("subpage",sql))
                # db.execSQL("subpage","set names utf8")
                db.insert("subpage",
                          url=link[1],
                          title=attr[0],
                          gongsi=attr[1],
                          person=attr[2],
                          time=attr[3],
                          user=attr[4],
                          flag=str(save))
                #hdb.put()
            else:
                ##print  "OK"
                sql = "url = '%s'" % (link[1])
                sql = "select flag from subpage where %s" % sql
                # sql = "url = '%s'" % (link[1])
                if bool(db.selectSQL("subpage", sql)[0]['flag']) == False:
                    sql = "url = '%s'" % (link[1])
                    # title = attr[0], gongsi = attr[1], person = attr[2], time = attr[3], user = attr[4], flag = str(save)
                    db.update(title=attr[0],
                              gongsi=attr[1],
                              person=attr[2],
                              time=attr[3],
                              user=attr[4],
                              flag=str(save),
                              where=sql)
                else:
                    print "Ok"

    # 存入 Hbase

    pass
Example #24
0
def getURL(db, idu):
    sql = "select url from urllist where id = " + str(idu) + ";"
    finalRt = MySQL.query(db, sql)
    if len(finalRt) == 0:
        return None
    return finalRt[0][0]
Example #25
0
from MongoDB import *

print("-------Club Deportivo--------")
print("| 1 | Registrar Persona     |")
print("| 2 | Guardar Persona       |")
print("| 3 | Registrar prestamo    |")
print("| 4 | Registrar Productos   |")
print("| 5 | Guardar Prestamo      |")
print("| 6 | Registrar Devolución  |")
print("| 7 | Crear Excel Personas  |")
print("| 8 | Crear Excel Prestamos |")
print("| 9 | Crear Excel Materiales|")
print("| 10| Cerrar Aplicación     |")
print("-----------------------------")
#Conexion a base de datos
newdb = MySQL()
print(newdb.Conexion())
newdb.createTablePerson()
newdb.createTablaMateriales()
#------------------------------
#Conexion a MongoDB
newMongo = MongoDB()
print(newMongo.mongoConexion())

newMongo.createDataBase(input("Ingresa el nombre de la base de Datos: "))
newMongo.crearTabla(input("Ingresa el nombre de la Tabla: "))
newMongo.actualizarFecha(int(input("Ingresa el ID: ")))
print(newMongo.actualizarFecha)
#------------------------------
numero = 0
respuesta = "s"
Example #26
0
import Download, Parse, MySQL
import datetime

start = datetime.datetime(  # inclusive
    year=2005,
    month=2,
    day=18,
    hour=0,
    minute=0,
    second=0,
    microsecond=0  # has to be in .1 sec increments
)
end = datetime.datetime(  # exclusive
    year=2005,
    month=2,
    day=19,
    hour=0,
    minute=0,
    second=0,
    microsecond=0  # has to be in .1 sec increments/ 1000000 microseconds
    # eg. microsecond=100000
    # eg. microsecond=200000
)

startdt = datetime.datetime.now()
data = MySQL.get_data("HAL", start, end)
print(data)
print(datetime.datetime.now() - startdt)
 def getConnection(self):
     return MySQL.getConnection(Configuration.SessionHandler_MySQLAlias)
Example #28
0
                update_sql = 'update Courts set CourtId= ' + court_id + ' where CourtCityId="' + court_city_id + '" and CourtSubId="' + court_sub_id + '"'
                mysql.upsert(select_sql, insert_sql, update_sql)
        print("end to get court list and insert into DB")

    def spider_and_upsert_court_info(self, court_list_url, court_item_regex):
        print("start to get court list and insert into DB")
        court_info_list = self.get_court_data(court_list_url, court_item_regex)
        for court_info in court_info_list:
            if court_info.__len__() > 1:
                court_city_id = court_info[0]
                court_sub_id = court_info[1]
                court_name = court_info[2]
                auction_count = court_info[3]
                select_sql = 'select count(*) from Courts where CourtCityId="' + court_city_id + '" and CourtSubId="' + court_sub_id + '"'
                insert_sql = 'insert into Courts (CourtCityId, CourtSubId, CourtId, CourtName, AuctionCount) values ("' + court_city_id + '","' + court_sub_id + '","' + court_sub_id + '","' + court_name + '",' + auction_count + ')'
                update_sql = 'update Courts set AuctionCount= ' + auction_count + ' where CourtCityId="' + court_city_id + '" and CourtSubId="' + court_sub_id + '"'
                mysql.upsert(select_sql, insert_sql, update_sql)
        print("end to get court list and insert into DB")


if __name__ == '__main__':
    mysql = MySQL.MySQL('auction_spider_ali')
    court_util = CourtUtil()
    # court_util.spider_and_upsert_court_info('https://sf.taobao.com/court_list.htm', r'<a href="\S*?\/(\d+)\/(\d+)\?\S*?" target="_blank" \S*?>(\S*?)</a>\s*<span class="iconfont-sf">\((\d+)')
    court_util.spider_and_upsert_court_info(
        'https://sf.taobao.com/court_list.htm',
        r'<a href="\S*?\/(\d+)\/(\d+)\S*?" \S+>\s*(\S+)\s*</a>\s*</span>\s*<span class="iconfont-sf">\((\d+)'
    )
    court_list = mysql.get_courts()
    print(court_list)
Example #29
0
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#Author:Rain Wang
#E-mail:[email protected]

#实现某功能,且是实现的所有代码的集合
#模块儿有两种存在方式:.py  "文件夹"
#模块儿:1>自己写的模块儿;2>别人写的模块儿.

import MySQL
import sys
sys.path.append('/Users/Rain/Python/')  #添加模块儿的环境变量
sys.path.append('/Users/Rain/Python/day05/')
import module
import django
sys.argv
from sys import argv
from MySQL import argv as test



if __name__=='__main__':
    MySQL.connection()
    MySQL.argv()
    print django.get_version()
    module.test()
Example #30
0
from MySQL import *
from MongoDB import *
import Adafruit_DHT
import time
from datetime import datetime

newSQL = MySQL()
newMongo = MongoDB()


class DHT:
    def __init__(self, name, DHTPIN):
        self.idName = name
        self.sensor = Adafruit_DHT.DHT11
        self.DHT11_pin = DHTPIN
        self.datos = (0, 0, "")
        self.temperature = 0
        self.humidity = 0
        self.type = 'DHT'
        newSQL.Conexion()
        newMongo.mongoConexion()

    def read(self):
        self.humidity, self.temperature = Adafruit_DHT.read(
            self.sensor, self.DHT11_pin)
        if self.humidity is not None and self.temperature is not None:
            self.ahora = datetime.now()
            self.fecha = self.ahora.strftime("%Y-%m-%d %H:%M:%S")
            self.datos = (self.temperature, self.humidity, self.fecha)
            time.sleep(1)