class Bot(): def __init__(self, config): self.url = config.get_url() self.sources = None self.stories = None def load(self): self.sources = Sources(self.url) self.stories = Stories(self.sources) return self.stories.load() def start(self, url): message = 'Бот для сайта {0}'.format(url) return message def help(self): message = "/get - читать истории из: \n\t{0}\n"\ "/random - случайные истории\n"\ "/stop - прервать диалог с ботом".format( '\n\t'.join(['{0}'.format(y) for (x,y) in self.stories.get_description().items()])) return message def random(self, num=None, site_names=None): if site_names is None: site_names = list(self.stories.get_names().keys()) sites = list(self.stories.get_names().values()) messages = [] stories = self.stories.get(num=num, site_names=site_names, sites=sites, random=True) for s in stories: messages.append(s.get().get('story')) return messages def get(self, num=None, site_names=None): if site_names is None: site_names = list(self.stories.get_names().keys()) sites = list(self.stories.get_names().values()) messages = [] stories = self.stories.get(num=num, site_names=site_names, sites=sites) for s in stories: messages.append(s.get().get('story')) return messages def get_sources_sites(self): sites = set() for sites_list in self.sources.get(): for site in sites_list: sites.add(site.get('site')) return list(sites) def get_sources_names(self, site): names = set() for sites_list in self.sources.get(): for s in sites_list: if s.get('site') == site: names.add((s.get('name'), s.get('desc'))) return list(names)
class SourcesTest(object): def __init__(self): self.photostore_sources = Sources(True) self.photostore_sources.create() def test_sources(self): curtime = str(time.time()) self.photostore_sources.put('1', 'foo', 'Foo', 'fa-user') self.photostore_sources.put('1', 'bar', 'Bar', 'fa-user') self.photostore_sources.put('1', 'goo', 'Goo', 'fa-user') self.photostore_sources.put('1', 'gopa', 'Gopa Kumar', 'fa-user') self.photostore_sources.put('1', 'blar', 'Blar', 'fa-user') data = self.photostore_sources.get('1') for d in data: print 'GET: data source %s, description %s, icon, %s act %s\n' % \ (d['g_uid'], d['SourceDescription'], d['SourceIcon'], d['SourceAccount']) data = self.photostore_sources.get('1', 'foo') for d in data: print 'QUERY: data source %s, description %s, icon %s, act %s\n' % \ (d['g_uid'], d['SourceDescription'], d['SourceIcon'], d['SourceAccount'])
def add_media_process(title, imdb): count = 0 from player import getSetting, load_settings import anidub, hdclub, nnmclub, rutor, soap4me, bluebird, kinohd settings = load_settings() anidub_enable = getSetting('anidub_enable') == 'true' hdclub_enable = False bluebird_enable = getSetting('bluebird_enable') == 'true' nnmclub_enable = getSetting('nnmclub_enable') == 'true' rutor_enable = getSetting('rutor_enable') == 'true' soap4me_enable = getSetting('soap4me_enable') == 'true' kinohd_enable = getSetting('kinohd_enable') == 'true' class RemoteDialogProgress: progress_file_path = filesystem.join(addon_data_path(), '.'.join([imdb, 'progress'])) def update(self, percent, *args, **kwargs): with filesystem.fopen(self.progress_file_path, 'w') as progress_file: progress_file.write(str(percent) + '\n') progress_file.write('\n'.join(args).encode('utf-8')) def close(self): try: filesystem.remove(self.progress_file_path) except: pass settings.progress_dialog = RemoteDialogProgress() p = [] from log import dump_context #try: if True: if anidub_enable and imdb.startswith('sm'): with dump_context('anidub.search_generate'): c = anidub.search_generate(title, settings, p) count += c if imdb.startswith('tt'): #if hdclub_enable: # c = hdclub.search_generate(title, imdb, settings, p) # count += c if bluebird_enable: with dump_context('bluebird.search_generate'): c = bluebird.search_generate(title, imdb, settings, p) count += c if rutor_enable: with dump_context('rutor.search_generate'): c = rutor.search_generate(title, imdb, settings, p) count += c if kinohd_enable: with dump_context('kinohd.search_generate'): c = kinohd.search_generate(title, imdb, settings, p) count += c if nnmclub_enable: with dump_context('nnmclub.search_generate'): c = nnmclub.search_generate(title, imdb, settings, p) count += c #if soap4me_enable: # count += soap4me.search_generate(title, imdb, settings) #except BaseException as e: # log.print_tb(e) if p: path = filesystem.join(addon_data_path(), imdb + '.strm_path') with filesystem.fopen(path, 'w') as f: f.write(p[0].encode('utf-8')) settings.progress_dialog.close() if count: import xbmc if not xbmc.getCondVisibility('Library.IsScanningVideo'): if p and p[0]: path = p[0] if path.endswith('.strm'): type = 'movies' else: type = 'tvshows' base_path = filesystem.dirname(p[0]) from sources import Sources srcs = Sources() for src in srcs.get('video', normalize=False): src_path_basename = filesystem.basename( src.path.rstrip('\\/')) if src_path_basename == base_path: #base_path.lower().replace('\\', '/') in src.path.lower().replace('\\', '/'): path_update = src.path if type == 'tvshows': if src.path.startswith('smb://'): path_update = src.path path_update = path_update.strip( '\\/') + '/' + filesystem.basename(path) else: path_update = filesystem.join( src.path, filesystem.basename(path)) log.debug(path_update) xbmc.executebuiltin('UpdateLibrary("video","%s")' % path_update.encode('utf-8')) #xbmc.executebuiltin('UpdateLibrary("video")') else: xbmc.executebuiltin('UpdateLibrary("video")') xbmc.sleep(250) while xbmc.getCondVisibility('Library.IsScanningVideo'): xbmc.sleep(100) path = filesystem.join(addon_data_path(), imdb + '.ended') with filesystem.fopen(path, 'w') as f: f.write(str(count))
def get_user_sources(username): src = Sources() src.create() return src.get(username)