示例#1
0
def CreateSession(apikey):
    Auth, SessionId, StatusMessageSession = BYBAPI.tmdb_session(apikey)
    columns = {
        "columns": {
            "auth": "TEXT",
            "sessionid": "TEXT",
            "statusmessage": "TEXT",
            "sessiontime": "TEXT"
        }
    }
    koding.Create_Table(table, columns)
    if Auth == False:
        BYB.Notify(title=str(addon_name),
                   message='Failed to create session\nBecause ' +
                   str(StatusMessageSession) +
                   '\nPlease check settings if using own API Key')
    else:
        add = {
            "auth": Auth,
            "sessionid": SessionId,
            "statusmessage": StatusMessageSession,
            "sessiontime": DateTimeNow
        }
        koding.Add_To_Table(table, add)
    return Auth, SessionId, StatusMessageSession
def CheckSession(apikey):
	hour = datetime.timedelta(minutes=60)
	results = koding.Get_All_From_Table(table)
	for item in results:
		Auth = item.get('auth',False)
		Auth = True if Auth == 'True' else False
		SessionId = item.get('sessionid','')
		StatusMessageSession = item.get('statusmessage','')
		SessionTime = item.get('sessiontime','2018-04-30 23:25:13.671000')
		SessionTime = dparser.parse(SessionTime)
		EndSessionTime = SessionTime+hour
	if DateTimeNow > EndSessionTime:
		BYB.Notify(title=str(addon_name),message='TMDB Session has expired creating new one')
		koding.Remove_Table(table)
		Auth,SessionId,StatusMessageSession = CreateSession(apikey)
	return Auth,SessionId,StatusMessageSession
def PopUpNotice():
    raw_notice = OpenURL(_Edit.PopUpNotice,
                         timeout=500,
                         cookiejar=BYB.cookie_name_create(_Edit.PopUpNotice))
    xml_notice = BeautifulSOAP(raw_notice,
                               convertEntities=BeautifulStoneSoup.XML_ENTITIES)
    BYB.headers_create(addon_cache,
                       table='pop_message',
                       headers='popupdate,displaydate')
    show = False
    if isinstance(xml_notice, BeautifulSOAP):
        if len(xml_notice('notify')) > 0:
            NotifingData = xml_notice('notify')
            for NotifyData in NotifingData:
                message = ''
                date = None
                header = ''
                freq = ''
                try:
                    header = NotifyData('header')[0].string
                    freq = NotifyData('freq')[0].string
                    message = NotifyData('message')[0].string
                    date = NotifyData('date')[0].string
                except:
                    pass
    DisplayDateCheck = BYB.check_is_in_DB_table(
        addon_cache,
        table='pop_message',
        row_header='displaydate',
        check_item=datetime.datetime.today().strftime('%Y-%m-%d'))
    OnceDisplayCheck = BYB.check_is_in_DB_table(addon_cache,
                                                table='pop_message',
                                                row_header='popupdate',
                                                check_item=date)
    BYB.write_to_DB(addon_cache,
                    table='pop_message',
                    headers='popupdate,displaydate',
                    items=(date,
                           datetime.datetime.today().strftime('%Y-%m-%d')))
    Dolog(datetime.datetime.today().strftime('%Y-%m-%d'), line_info=True)
    Dolog(BYB.check_is_in_DB_table(
        addon_cache,
        table='pop_message',
        row_header='displaydate',
        check_item=datetime.datetime.today().strftime('%Y-%m-%d')),
          line_info=True)
    if freq == 'every':
        show = True
    elif freq == 'daily' and DisplayDateCheck == False:
        Dolog('show daily', line_info=True)
        show = True
    elif freq == 'once' and OnceDisplayCheck == False:
        show = True
    else:
        Dolog('key word for freq wrong either every,daily,once')
    if show == True:
        if len(message) > 0:
            try:
                from libs import customgui
                customgui.PopUpDialog(header=header, text=message)
            except:
                BYB.Notify(title='Error',
                           message='Error in displaying Pop Up Message')
        else:
            BYB.Notify(title='Error',
                       message='Error in displaying Pop Up Message')
    else:
        pass