コード例 #1
0
    def RegisterMagnetLink(self, magnetLink, bot, chat_id):
        ds = dsdownload.dsdownload()

        log.info('DS Torrent download for magnetLink')

        ret, items = ds.db_query("SELECT * FROM USER_SETTING WHERE username='******';")
        if ret == False:
            log.info('DS Download User Setting not found..')
            return False

        ds_user = items[0][0]
        sh_dir = items[0][2]
        log.info('DS Download Config, Download Directory : %s', sh_dir)

        log.info("DS Download, user:'******', DownloadPath:'%s', Magnet Link : '%s'", ds_user, sh_dir.decode('utf-8'), magnetLink)

        query = u"INSERT INTO download_queue (username, url, status, filename, pid, created_time, destination) VALUES ('%s', '%s', 1, 'Magnet Link', %d, %d, '%s');" % (ds_user, magnetLink, os.getpid(), int(time.time()), sh_dir.decode('utf-8')) 
        log.debug(query)
        ret = ds.db_exec(query.encode('utf-8'))
        log.info('torrent download query complete')

        hide_keyboard = {'hide_keyboard': True}
        if ret == True:
            msg = 'Magnet Link 가 등록 되었습니다.\n다운로드를 시작합니다.'
            bot.sendMessage(chat_id, msg, reply_markup=hide_keyboard) 
        else:
            bot.sendMessage(chat_id, u'Magnet Link 등록 실패', reply_markup=hide_keyboard) 

        return True
コード例 #2
0
    def ReceiveTorrentFile(self, fileid, file_name, file_ext, file_type, bot, chat_id):
        watch_dir = main.botConfig.GetTorrentWatchDir()
        filename = file_name + "." + file_ext

        ds = dsdownload.dsdownload()

        log.info('DS Torrent download')

        ret, items = ds.db_query("SELECT * FROM USER_SETTING WHERE username='******';")
        if ret == False:
            log.info('DS Download User Setting not found..')
            return

        ds_user = items[0][0]
        #watch_dir = items[0][5]

        log.info('ReceiveTorrentFile, ds_user:%s, Watch:%s', ds_user, watch_dir.decode('utf-8'))

        #bot.download_file(fileid, watch_dir + file_name )

        log.debug('downoad success')
        
        log.info('%s download success', filename.decode('utf-8'))

        hide_keyboard = {'hide_keyboard': True}
        #msg = file_name.decode('utf-8') + ' 파일을 ' + watch_dir.decode('utf-8') + ' 경로에 다운로드 하였습니다';
        bot.sendMessage(chat_id, 'Torrent File Download...', reply_markup=hide_keyboard) 

        return True
コード例 #3
0
ファイル: torrent.py プロジェクト: coolhong/xpebot
    def ReceiveTorrentFile(self, fileid, file_name, file_ext, file_type, bot, chat_id):
        watch_dir = main.botConfig.GetTorrentWatchDir()
        filename = file_name + "." + file_ext

        ds = dsdownload.dsdownload()

        log.info('DS Torrent download')

        ret, items = ds.db_query("SELECT * FROM USER_SETTING WHERE username='******';")
        if ret == False:
            log.info('DS Download User Setting not found..')
            return

        ds_user = items[0][0]
        #watch_dir = items[0][5]

        log.info('ReceiveTorrentFile, ds_user:%s, Watch:%s', ds_user, watch_dir.decode('utf-8'))

        bot.download_file(fileid, watch_dir + file_name )

        log.debug('downoad success')
        
        log.info('%s download success', filename.decode('utf-8'))

        hide_keyboard = {'hide_keyboard': True}
        #msg = file_name.decode('utf-8') + ' 파일을 ' + watch_dir.decode('utf-8') + ' 경로에 다운로드 하였습니다';
        bot.sendMessage(chat_id, 'Torrent File Download...', reply_markup=hide_keyboard) 

        return True
コード例 #4
0
ファイル: BotManager.py プロジェクト: parkjongdae/xpebot
    def on_chat_message(self, msg):

        try:
            flavor = telepot.flavor(msg)

            # inline query test code...
            # Have to answer inline query to receive chosen result
            log.info('flavor : %s', flavor)
            if flavor == 'inline_query':
                log.info('inline query!!')
                query_id, from_id, query_string = telepot.glance(msg,
                                                                 flavor=flavor)
                log.info('Inline Query: id:%s, from:%d, msg:%s', query_id,
                         from_id, query_string)

                articles = [{
                    'type': 'article',
                    'id': 'abc',
                    'title': 'ABC',
                    'message_text': 'Good morning'
                }]
                self.bot.answerInlineQuery(query_id, articles)
                return

            content_type, chat_type, chat_id = telepot.glance(msg)

            log.info("ContentType : '%s'", content_type)
            log.info("chat_type : '%s'", chat_type)
            log.info("chat_id : %d", chat_id)

            # Message to Log Write
            self.PrintMsg(msg)

            # Valid User Check
            if not chat_id in self.valid_user:
                log.info("Invalid user : %d", chat_id)
                return

            log.debug("chat_type:'%s'", chat_type)
            if chat_type == 'group':
                groupMsg = self.group_command_handler(unicode(msg['text']),
                                                      chat_id)
                log.info("Group Message : %s", groupMsg)
                return

            if content_type is 'text':
                self.command_handler(unicode(msg['text']), chat_id)
                log.info(msg['text'])
                return

            if content_type is 'document':
                file_name = msg['document']['file_name']
                file_id = msg['document']['file_id']
                file_ext = os.path.splitext(file_name)
                file_type = msg['document']['mime_type']
                self.file_handler(file_name, file_id, file_ext[1], file_type,
                                  chat_id)
                return
        except Exception, e:
            log.error(e, exc_info=True)
コード例 #5
0
ファイル: weather.py プロジェクト: Raccoon-git/xpebot
    def GetDongneWether(self, bot, chat_id, dongne_name):
        query = u"select code, sido, gugun, dong from kma_dongne where dong like '%" + dongne_name + "%';"
        log.debug(query)

        hide_keyboard = {'hide_keyboard': True}

        if dongne_name == u'전국 날씨':
            today, tomorrow = self.GetWeatherSummary(u'전국날씨')
            bot.sendMessage(chat_id, today, reply_markup=hide_keyboard)
            return

        db = sqlite3.connect(self.db_path)
        cursor = db.cursor()
        cursor.execute(query)
        rowdata = cursor.fetchall()

        before_sido = ''

        # 동네 이름이 여러개 있을 경우 모두 출력
        for row in rowdata:
            code = str(row[0])
            sido = row[1]
            gugun = row[2]
            dong = row[3]

            dong_url = "http://www.kma.go.kr/wid/queryDFSRSS.jsp?zone=" + code + '00'

            log.info('dongne weather url : %s', dong_url)

            data = urllib.urlopen(dong_url)

            sp = BeautifulSoup.BeautifulSoup(data)

            dongne = sp.findAll('data', attrs={'seq': '0'})

            # 풍속의 소수점이 길게 나오는 케이스로 인해 소수점 2자리까지만 표현
            ws = round(float(dongne[0].find('ws').text), 2)

            weather_info = sido + ' ' + gugun + ' ' + dong + u' 날씨\n'\
                            u'날씨 : ' + dongne[0].find('wfkor').text + u'\n'\
                            u'온도 : ' + dongne[0].find('temp').text + u"℃\n"\
                            u'풍속 : ' + str(ws) + u"m/s\n"\
                            u'풍향 : ' + dongne[0].find('wdkor').text + u"풍\n"\
                            u'습도 : ' + dongne[0].find('reh').text + u"%\n"\
                            u'강수 확률 : ' + dongne[0].find('pop').text + u"%\n"

            sp.close()
            data.close()

            bot.sendMessage(chat_id, weather_info, reply_markup=hide_keyboard)

            # 시도별 날씨 요약본 가져 오기
            if before_sido != sido:
                today, tomorrow = self.GetWeatherSummary(sido)
                bot.sendMessage(chat_id, today, reply_markup=hide_keyboard)

            before_sido = sido

        cursor.close()
        db.close()
コード例 #6
0
ファイル: torrent.py プロジェクト: acidpop/xpebot
    def RegisterMagnetLink(self, magnetLink, bot, chat_id):
        ds = dsdownload.dsdownload()

        log.info('DS Torrent download for magnetLink')

        ret, items = ds.db_query("SELECT * FROM USER_SETTING WHERE username='******';")
        if ret == False:
            log.info('DS Download User Setting not found..')
            return False

        ds_user = items[0][0]
        sh_dir = items[0][2]
        log.info('DS Download Config, Download Directory : %s', sh_dir)

        log.info("DS Download, user:'******', DownloadPath:'%s', Magnet Link : '%s'", ds_user, sh_dir.decode('utf-8'), magnetLink)

        query = u"INSERT INTO download_queue (username, url, status, filename, pid, created_time, destination) VALUES ('%s', '%s', 1, 'Magnet Link', %d, %d, '%s');" % (ds_user, magnetLink, os.getpid(), int(time.time()), sh_dir.decode('utf-8')) 
        log.debug(query)
        ret = ds.db_exec(query.encode('utf-8'))
        log.info('torrent download query complete')

        hide_keyboard = {'hide_keyboard': True}
        if ret == True:
            msg = 'Magnet Link 가 등록 되었습니다.\n다운로드를 시작합니다.'
            bot.sendMessage(chat_id, msg, reply_markup=hide_keyboard) 
        else:
            bot.sendMessage(chat_id, u'Magnet Link 등록 실패', reply_markup=hide_keyboard) 

        return True
コード例 #7
0
ファイル: BotManager.py プロジェクト: parkjongdae/xpebot
 def SendMarkupMessage(self, chat_id, message, show_keyboard):
     log.debug(message)
     if show_keyboard == '':
         self.sendMessage(chat_id, message, parse_mode='Markdown')
     else:
         self.sendMessage(chat_id,
                          message,
                          parse_mode='Markdown',
                          reply_markup=show_keyboard)
コード例 #8
0
ファイル: BotManager.py プロジェクト: parkjongdae/xpebot
 def on_close(self, exception):
     if type(exception) == telepot.helper.WaitTooLong:
         log.debug('Wait Timeout')
         if self.cur_mode != '':
             #self.sender.sendMessage('입력 시간이 초과 되었습니다', reply_markup=self.hide_keyboard)
             self.cur_mode = ''
     else:
         log.error('on_close - exception :')
         log.error(exception)
         log.exception("on_close - exception :")
         traceback.print_exc(file=sys.stdout)
コード例 #9
0
ファイル: BotManager.py プロジェクト: ludishur/xpebot
 def on_close(self, exception):
     if type(exception) == telepot.helper.WaitTooLong:
         log.debug('Wait Timeout')
         if self.cur_mode != '':
             #self.sender.sendMessage('입력 시간이 초과 되었습니다', reply_markup=self.hide_keyboard)
             self.cur_mode = ''
     else:
         log.error('on_close - exception :')
         log.error(exception)
         log.exception("on_close - exception :")
         traceback.print_exc(file=sys.stdout)
コード例 #10
0
ファイル: BotManager.py プロジェクト: ludishur/xpebot
    def on_chat_message(self, msg):

        try:
            flavor = telepot.flavor(msg)

            # inline query test code...
            # Have to answer inline query to receive chosen result
            log.info('flavor : %s', flavor)
            if flavor == 'inline_query':
                log.info('inline query!!')
                query_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
                log.info('Inline Query: id:%s, from:%d, msg:%s', query_id, from_id, query_string)

                articles = [{'type': 'article',
                                 'id': 'abc', 'title': 'ABC', 'message_text': 'Good morning'}]
                self.bot.answerInlineQuery(query_id, articles)
                return

            content_type, chat_type, chat_id = telepot.glance(msg)

            log.info("ContentType : '%s'", content_type)
            log.info("chat_type : '%s'", chat_type)
            log.info("chat_id : %d", chat_id)

            # Message to Log Write
            self.PrintMsg(msg)

            # Valid User Check
            if not chat_id in self.valid_user:
                log.info("Invalid user : %d", chat_id)
                return

            log.debug("chat_type:'%s'", chat_type)
            if chat_type == 'group':
                groupMsg = self.group_command_handler(unicode(msg['text']), chat_id)
                log.info("Group Message : %s", groupMsg)
                return


            if content_type is 'text':
                self.command_handler(unicode(msg['text']), chat_id)
                log.info(msg['text'])
                return

            if content_type is 'document':
                file_name = msg['document']['file_name']
                file_id = msg['document']['file_id']
                file_ext = os.path.splitext(file_name)
                file_type = msg['document']['mime_type']
                self.file_handler(file_name, file_id, file_ext[1], file_type, chat_id)
                return
        except Exception, e:
            log.error(e, exc_info=True)
コード例 #11
0
ファイル: torrent.py プロジェクト: HasibulKabir/xpebot
    def ReceiveTorrentFile(self, fileid, file_name, file_ext, file_type, bot,
                           chat_id):
        watch_dir = main.botConfig.GetTorrentWatchDir()
        filename = file_name + "." + file_ext

        ds = dsdownload.dsdownload()

        log.info('DS Torrent download')

        ret, items = ds.db_query(
            "SELECT * FROM USER_SETTING WHERE username='******';")
        if ret == False:
            log.info('DS Download User Setting not found..')
            return

        ds_user = items[0][0]
        #watch_dir = items[0][5]

        log.info('ReceiveTorrentFile, ds_user:%s, Watch:%s', ds_user,
                 watch_dir.decode('utf-8'))

        try:
            filename = filename.encode('utf-8')
        except UnicodeDecodeError:
            log.info(
                "ReceiveTorrentFile Exception : it was not a ascii-encoded unicode string"
            )
            filename = fileid + '.torrent'
        except UnicodeEncodeError:
            log.info(
                "ReceiveTorrentFile Exception : It may have been an ascii-encoded unicode string"
            )
            filename = fileid + '.torrent'
        except:
            log.info("ReceiveTorrentFile Exception : it is wrong string")
            filename = fileid + '.torrent'

        bot.download_file(fileid, watch_dir + file_name)

        log.debug('downoad success')

        log.info('[%s] download success', filename)

        hide_keyboard = {'hide_keyboard': True}
        #msg = file_name.decode('utf-8') + ' 파일을 ' + watch_dir.decode('utf-8') + ' 경로에 다운로드 하였습니다';
        #msg = "%s 파일을\n'%s'\n경로에 다운로드 하였습니다" % (filename.encode('utf-8'), watch_dir.encode('utf-8'))
        msg = 'Torrent 파일을 Watch 경로에 다운로드 하였습니다\n잠시 후 다운로드가 시작됩니다'
        bot.sendMessage(chat_id, msg, reply_markup=hide_keyboard)

        return True
コード例 #12
0
ファイル: torrent.py プロジェクト: HasibulKabir/xpebot
    def torrent_download(self, selected, bot, chat_id):
        ds = dsdownload.dsdownload()

        log.info('DS Torrent download')

        if type(selected) is int == False:
            log.info('Torrent Download, Selected number type is not int!')
            bot.sendMessage(chat_id, u'입력값 오류')
            return False

        ret, items = ds.db_query(
            "SELECT * FROM USER_SETTING WHERE username='******';")
        if ret == False:
            log.info('DS Download User Setting not found..')
            return False

        ds_user = items[0][0]
        sh_dir = items[0][2]
        log.info('DS Download Config, Download Directory : %s', sh_dir)

        index = int(selected.split('.')[0]) - 1
        magnet = self.navi.entries[index].link

        log.info(
            "DS Download, user:'******', DownloadPath:'%s', Magnet Link : '%s'",
            ds_user, sh_dir.decode('utf-8'), magnet)

        query = u"INSERT INTO download_queue (username, url, status, filename, pid, created_time, destination) VALUES ('%s', '%s', 1, 'Magnet Link', %d, %d, '%s');" % (
            ds_user, magnet, os.getpid(), int(
                time.time()), sh_dir.decode('utf-8'))
        log.debug(query)
        ret = ds.db_exec(query.encode('utf-8'))
        log.info('torrent download query complete')

        hide_keyboard = {'hide_keyboard': True}
        if ret == True:
            msg = self.navi.entries[index].title + u' 다운로드를 시작합니다'
            bot.sendMessage(chat_id, msg, reply_markup=hide_keyboard)
            self.navi.clear()
        else:
            bot.sendMessage(chat_id, u'다운로드 실패', reply_markup=hide_keyboard)

        return True
コード例 #13
0
    def GetWeatherSummary(self, LocalName):
        log.info('GetWeatherSummary : ' + LocalName)
        sumurl = self.GetSummaryUrl(LocalName)
        
        log.debug('url : ' + sumurl)

        data = urllib.urlopen(sumurl)

        soup = BeautifulSoup.BeautifulSoup(data)

        week_summary = soup.findAll('table', attrs={'class':'table_announcementtime'})

        today_summary = LocalName + ' ' + week_summary[0].find('caption').text + '\n' + \
                        week_summary[0].find('p').text.replace(u'다.', u'다.\n') + '\n'
        tomorrow_summary =  LocalName + ' ' + week_summary[1].find('caption').text + '\n' + \
                            week_summary[1].find('p').text.replace(u'다.', u'다.\n') + '\n'

        soup.close()
        data.close()
        
        return today_summary, tomorrow_summary
コード例 #14
0
ファイル: torrent.py プロジェクト: coolhong/xpebot
    def torrent_download(self, selected, bot, chat_id):
        ds = dsdownload.dsdownload()

        log.info('DS Torrent download')

        if type(selected) is int == False:
            log.info('Torrent Download, Selected number type is not int!')
            bot.sendMessage(chat_id, u'입력값 오류') 
            return False

        ret, items = ds.db_query("SELECT * FROM USER_SETTING WHERE username='******';")
        if ret == False:
            log.info('DS Download User Setting not found..')
            return False

        ds_user = items[0][0]
        sh_dir = items[0][2]
        log.info('DS Download Config, Download Directory : %s', sh_dir)
       
        index = int(selected.split('.')[0]) - 1 
        magnet = self.navi.entries[index].link

        log.info("DS Download, user:'******', DownloadPath:'%s', Magnet Link : '%s'", ds_user, sh_dir.decode('utf-8'), magnet)

        query = u"INSERT INTO download_queue (username, url, status, filename, pid, created_time, destination) VALUES ('%s', '%s', 1, 'Magnet Link', %d, %d, '%s');" % (ds_user, magnet, os.getpid(), int(time.time()), sh_dir.decode('utf-8')) 
        log.debug(query)
        ret = ds.db_exec(query.encode('utf-8'))
        log.info('torrent download query complete')

        hide_keyboard = {'hide_keyboard': True}
        if ret == True:
            msg = self.navi.entries[index].title + u' 다운로드를 시작합니다'
            bot.sendMessage(chat_id, msg, reply_markup=hide_keyboard) 
            self.navi.clear()
        else:
            bot.sendMessage(chat_id, u'다운로드 실패', reply_markup=hide_keyboard) 

        return True
コード例 #15
0
def smart_fill(variable_name):
    '''
    '''
    variable_name = variable_name.lower()

    flag = False

    for filled_value, variable_name_list in parameter_name_knowledge.items():

        for variable_name_db in variable_name_list:

            if variable_name_db == variable_name:

                flag = True

                return filled_value

    if not flag:

        msg = '[smart_fill] Failed to find a value for parameter with name "' + variable_name + '".'
        log.debug(msg)

        return 'UNKNOWN'
コード例 #16
0
ファイル: BotManager.py プロジェクト: ludishur/xpebot
 def SendMarkupMessage(self, chat_id, message, show_keyboard):
     log.debug(message)
     if show_keyboard == '':
         self.sendMessage(chat_id, message, parse_mode='Markdown')
     else:
         self.sendMessage(chat_id, message, parse_mode='Markdown', reply_markup=show_keyboard)
コード例 #17
0
ファイル: BotManager.py プロジェクト: parkjongdae/xpebot
 def SendHtmlMessage(self, chat_id, message):
     log.debug(message)
     self.sendMessage(chat_id, message, parse_mode='HTML')
コード例 #18
0
ファイル: BotManager.py プロジェクト: ludishur/xpebot
 def SendHtmlMessage(self, chat_id, message):
     log.debug(message)
     self.sendMessage(chat_id, message, parse_mode='HTML')
コード例 #19
0
ファイル: weather.py プロジェクト: acidpop/xpebot
    def GetDongneWether(self, bot, chat_id, dongne_name):
        query = u"select code, sido, gugun, dong from kma_dongne where dong like '%" + dongne_name + "%';"
        log.debug(query)

        hide_keyboard = {'hide_keyboard': True}

        if dongne_name == u'전국 날씨':
            today, tomorrow = self.GetWeatherSummary(u'전국날씨')
            bot.sendMessage(chat_id, today, reply_markup=hide_keyboard) 
            return
            
        db = sqlite3.connect(self.db_path)
        cursor = db.cursor()
        cursor.execute(query)
        rowdata = cursor.fetchall()

        
        before_sido = ''

        # 동네 이름이 여러개 있을 경우 모두 출력
        for row in rowdata:
            code = str(row[0])
            sido = row[1]
            gugun = row[2]
            dong = row[3]
        
            dong_url = "http://www.kma.go.kr/wid/queryDFSRSS.jsp?zone=" + code + '00'
            
            log.info('dongne weather url : %s', dong_url)
            
            data = urllib.urlopen(dong_url)
            
            sp = BeautifulSoup.BeautifulSoup(data)
            
            dongne = sp.findAll('data', attrs={'seq':'0'})

            # 풍속의 소수점이 길게 나오는 케이스로 인해 소수점 2자리까지만 표현
            ws = round(float(dongne[0].find('ws').text), 2)

            weather_info = sido + ' ' + gugun + ' ' + dong + u' 날씨\n'\
                            u'날씨 : ' + dongne[0].find('wfkor').text + u'\n'\
                            u'온도 : ' + dongne[0].find('temp').text + u"℃\n"\
                            u'풍속 : ' + str(ws) + u"m/s\n"\
                            u'풍향 : ' + dongne[0].find('wdkor').text + u"풍\n"\
                            u'습도 : ' + dongne[0].find('reh').text + u"%\n"\
                            u'강수 확률 : ' + dongne[0].find('pop').text + u"%\n"
            
            sp.close()
            data.close()

            bot.sendMessage(chat_id, weather_info, reply_markup=hide_keyboard) 

            # 시도별 날씨 요약본 가져 오기
            if before_sido != sido:
                today, tomorrow = self.GetWeatherSummary(sido)
                bot.sendMessage(chat_id, today, reply_markup=hide_keyboard)

            before_sido = sido
        
        cursor.close()
        db.close()