def main(): try: links_afisha = WebSource(config.URL_AFISHA_VLG).get_links_afisha() afisha_movies = [ WebSource(link).get_info_about_movie() for link in links_afisha ] Storer('database.txt').save('afisha', afisha_movies) links_temp = WebSource(url_premieres()).get_links_premieres() links_premieres = [ link for link in links_temp if link not in links_afisha ] premieres_movies = [ WebSource(link).get_info_about_movie() for link in links_premieres ] Storer('database.txt').save('premieres', premieres_movies) except Exception as err: logging.error(err) time.sleep(5) print("Error!")
def setUp(self): self.file_name = "testeo" self.extension_txt = "txt" self.extension_csv = "csv" self.matrix = ['9','3','8','4','7','5','1','6','2'],['1','4','6','9','3','2','7','5','8'],['7','5','2','8','6','1','9','4','3'],\ ['8','9','1','6','4','3','2','7','5'],['3','6','5','2','9','7','8','1','4'],['4','2','7','1','5','8','6','3','9'],\ ['5','8','3','7','2','6','4','9','1'],['2','7','9','3','1','4','5','8','6'],['6','1','4','5','8','9','3','2','7'] self.store01 = Storer(self.matrix, self.file_name, self.extension_txt) self.store02 = Storer(self.matrix, self.file_name, self.extension_csv)
def test_initialization_pkl(self): """ Test initialization procedure Expected one backup file after dump procedure """ s = Storer(dump_path=PATH_DUMPS, dump_name=DUMP_NAME, verbose=VERBOSE, compressed=False, _test=True) s.put(1, name="one") s.dump() s2 = Storer(dump_path=PATH_DUMPS, dump_name=DUMP_NAME, verbose=VERBOSE, compressed=False, _test=True) one = len(s2.backup_list) assert one == 1, f"Got something different: {one}" s._cleanup()
def handle_start(message): if not Storer('userdata.txt').check_user(str(message.chat.id)): msg = bot.send_message( message.chat.id, 'Выбирайте', reply_markup=markups.choice_buttons1 ) bot.register_next_step_handler(msg, ask_run_or_template) else: Storer('userdata.txt').save_user(str(message.chat.id)) msg = bot.send_message(message.chat.id, 'Введите название шаблона') bot.register_next_step_handler(msg, ask_template)
def test_separation(self): """ Test separation procedure """ s = Storer(dump_path=PATH_DUMPS, dump_name=DUMP_NAME, verbose=VERBOSE, compressed=False, separations=1, _test=True) s.put(1, name="one") # 1 s.put(2, name="two") # 2 s.put(3, name="three") # 3 s.put(4, name="four") # 4 s.dump() s2 = Storer(dump_path=PATH_DUMPS, dump_name=DUMP_NAME, verbose=VERBOSE, compressed=False, _test=True) length = len(s2.backup_list) assert length == 4, f"Got something different: {length}" s._cleanup()
def __init__(self, tp_url_real, context_path, context_file_path, base_iri, base_dir, info_dir, dataset_home, tmp_dir, triplestore_url=None): self.tp_url = triplestore_url self.base_iri = base_iri self.base_dir = base_dir self.info_dir = info_dir self.context_path = context_path self.dataset_home = URIRef(dataset_home) self.tmp_dir = tmp_dir self.tp_res = URIRef(tp_url_real) self.repok = Reporter(prefix="[DatasetHandler: INFO] ") self.reperr = Reporter(prefix="[DatasetHandler: ERROR] ") self.st = Storer(context_map={context_path: context_file_path}, repok=self.repok, reperr=self.reperr) self.st.set_preface_query( u"DELETE { ?res <%s> ?date } WHERE { ?res a <%s> ; <%s> ?date }" % (str(DatasetHandler.modified), str( DatasetHandler.dataset), str(DatasetHandler.modified)))
def test_long_loop_loading(self): """ Get method in loop: Checking for not overloading internal data dict """ s = Storer(dump_path=PATH_DUMPS, dump_name=DUMP_NAME, verbose=VERBOSE, compressed=False, separations=10000, _test= True) cycles = 1000 for idx in range(cycles): value = s.get(name=str(idx)) if not value: s.put(what=idx, name=str(idx)) s.dump() s2 = Storer(dump_path=PATH_DUMPS, dump_name=DUMP_NAME, verbose=VERBOSE, compressed=False, separations=10000, _test= True) for idx in range(cycles): value = s2.get(name=str(idx)) assert value == idx, f"Got something different: {value} != {idx}" s._cleanup()
def test_creating_pbz2(self): """ Test paths of the created instance (PBZ2) """ s = Storer(dump_path=PATH_DUMPS, dump_name=DUMP_NAME, verbose=VERBOSE, _test=True) s.put(1, name="one") s.dump() assert os.path.exists(os.path.expanduser(PATH_DUMPS) + DUMP_NAME + PBZ2) s._cleanup()
def test_backup_dumb_pbz2(self): """ Test backup creating """ s = Storer(dump_path=PATH_DUMPS, dump_name=DUMP_NAME, verbose=VERBOSE, _test=True) s.put(1, name="one") s.backup() assert os.path.exists(os.path.expanduser(PATH_DUMPS_BACKUP) + DUMP_NAME + PBZ2) s._cleanup()
def __init__(self, input_dir, output_dir=None, tmp_dir=None): self.input_dir = input_dir self.output_dir = output_dir self.tmp_dir = tmp_dir self.storer = Storer() self.name = self.__class__.__name__ self.repok = Reporter(prefix="[%s - INFO] " % self.name) self.repok.new_article() self.reper = Reporter(prefix="[%s - ERROR] " % self.name) self.reper.new_article()
def add_genres(message): genre = message.text Storer('userdata.txt').add_genre(str(message.chat.id), template, genre) msg = bot.send_message( message.chat.id, 'Выбирайте', reply_markup=markups.choice_buttons2 ) bot.register_next_step_handler(msg, add_genre_or_finish)
def ask_template(message): global template template = message.text Storer('userdata.txt').add_template(str(message.chat.id), template) msg = bot.send_message( message.chat.id, 'Добавьте жанры в шаблон', reply_markup=markups.choice_genres ) bot.register_next_step_handler(msg, add_genres)
def findMovies(userid): usersets = Storer('userdata.txt').get_usersets(str(userid)) afisha = Storer('database.txt').get_data('afisha') afisha_movies = get_info(usersets, afisha) if afisha_movies: for movie in afisha_movies: bot.send_message(userid, movie) else: bot.send_message(userid, "Из текущего репертуара подходящих фильмов нет") bot.send_message(userid, "Обзор среди премьер текущего месяца: ") time.sleep(1) premieres = Storer('database.txt').get_data('premieres') premieres_movies = get_info(usersets, premieres) if premieres: for movie in premieres_movies: bot.send_message(userid, movie) else: bot.send_message(userid, "Увы, и среди премьер подходящих фильмов нет") bot.send_message(userid, 'Готово', reply_markup=markups.start_markup)
def test_loading_separation_pbz2(self): """ Test separation procedure """ s = Storer(dump_path=PATH_DUMPS, dump_name=DUMP_NAME, verbose=VERBOSE, compressed=True, separations=1, _test=True) s.put(1, name="one") # _ s.put(2, name="two") # 0 s.put(3, name="three") # 1 s.put(4, name="four") # 2 s.dump() # 3 s2 = Storer(dump_path=PATH_DUMPS, dump_name=DUMP_NAME, verbose=VERBOSE, compressed=True, _test=True) one = s2.get(name="one") assert 1 == one, f"Got something different: {one}" two = s2.get(name="two") assert 2 == two, f"Got something different: {two}" three = s2.get(name="three") assert 3 == three, f"Got something different: {three}" four = s2.get(name="four") assert 4 == four, f"Got something different: {four}" s._cleanup()
def test_get_item_bpz2(self): """ Test get item procedure """ s = Storer(dump_path=PATH_DUMPS, dump_name=DUMP_NAME, verbose=VERBOSE, _test=True) s.put(1, name="one") s.put(2, name="two") three = s.get("three") assert three == False # "Should be False!" s.put(3, name="three") s.dump() # here is new data in storer three = s.get("three") assert three == 3, f"got something different: [{three}]" # "Should be 3!" s._cleanup()
def __init__(self, g_set=None, ts_url=None, base_dir=None, base_iri=None, tmp_dir=None, context_map={}): self.g = Graph() self.base_dir = base_dir self.base_iri = base_iri self.storer = Storer(context_map=context_map) self.tmp_dir = tmp_dir self.name = "SPACIN " + self.__class__.__name__ self.loaded = set() if g_set is not None: self.update_graph_set(g_set) if ts_url is None: self.ts = None else: self.ts = ConjunctiveGraph('SPARQLUpdateStore') self.ts.open((ts_url, ts_url))
if result is not None: prov = ProvSet( result, base_iri, context_path, info_dir, ResourceFinder( base_dir=base_dir, base_iri=base_iri, tmp_dir=temp_dir_for_rdf_loading, context_map={ context_path: context_file_path })) prov.generate_provenance() res_storer = Storer(result, context_map={ context_path: context_file_path }, dir_split=dir_split_number, n_file_item=items_per_file) res_storer.upload_and_store( base_dir, triplestore_url, base_iri, context_path, temp_dir_for_rdf_loading) prov_storer = Storer( prov, context_map={ context_path: context_file_path }, dir_split=dir_split_number, n_file_item=items_per_file) prov_storer.store_all(
#!/usr/bin/env python3 from storer import Storer import sys s = Storer() if s.get_value() != 0: print('Initial value incorrect.') sys.exit(1) s.set_value(42) if s.get_value() != 42: print('Setting value failed.') sys.exit(1) try: s.set_value('not a number') print('Using wrong argument type did not fail.') sys.exit(1) except TypeError: pass
import init_bot import telegram import os import pytz from datetime import datetime, timedelta from storer import Storer from user_info import UserInfo from telegram.ext import Updater, CommandHandler, CallbackQueryHandler, Job STORED_FILE = os.getenv('UNI_STORED_FILE', 'unison_bot_shelve.db') MENU, AWAIT_INPUT_GAME, AWAIT_MEETING_ANSWER = range(3) state = dict() users = {} users_store = Storer(STORED_FILE) forum_subscribers = dict() meeting_subscribers = [] komsostav = [] posts_from_forum = [] last_check_new_posts = 0 UPDATE_FORUM_POSTS_TIMEOUT_SEC = 10. * 60 DEL_FORUM_POSTS_TIMEOUT_SEC = 24 * 60. * 60 logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG)
from telegram.ext import CommandHandler, Filters, MessageHandler, Updater TOKEN = '' # TG bot token VK_TOKEN = '' # VK access token PUBLIC_ID = 0 # vk.com/wall<PUBLIC_ID>_... INTERVAL = 60 # Seconds IGNORE_TAGS = [] # ['#IGNORE', '#HASHTAGS'] # Enable logging logging.basicConfig(format='[%(asctime)s][%(levelname)s] - %(message)s', level=logging.INFO) logger = logging.getLogger(__name__) # Database storer = Storer('bot.db') def vk(method, params): params['access_token'] = VK_TOKEN params['v'] = 5.74 q = requests.post('https://api.vk.com/method/' + method, data=params) return json.loads(q.text) def start(bot, update): if storer.restore('cid') is None: update.message.reply_text( 'To get started, add me to the channel\'s administrators, ' 'then forward any message from the channel to this dialog')
def __post_init__(self): self.storer = Storer(exit_dump=False) self.g = veusz.Embedded(name=self.title, hidden=self.hidden) self.g.EnableToolbar() self.init_pages()
help="The directory where to look for duplicates.") arg_parser.add_argument("-o", "--output_file", dest="o_file", help="The file where to write the results.") arg_parser.add_argument( "--recursive", dest="rec", default=False, action="store_true", help="The process will consider also the subdir recursively.") args = arg_parser.parse_args() id_doc = {} s = Storer(context_map={context_path: context_file_path}) all_files = [] if args.rec: for cur_dir, cur_subdir, cur_files in os.walk(args.i_dir): for cur_file in cur_files: if cur_file.endswith(".json"): all_files += [cur_dir + os.sep + cur_file] else: for cur_file in os.listdir(args.i_dir): if cur_file.endswith(".json"): all_files += [args.i_dir + os.sep + cur_file] for rdf_path in all_files: cur_g = s.load(rdf_path, tmp_dir=temp_dir_for_rdf_loading) try:
from telegram import User from telegram.ext import Updater, CommandHandler import logging import checker import os from time import time, ctime from storer import Storer from cardinfo import CardInfo, ThresholdExceedListener from userinfo import UserInfo STORED_FILE = os.getenv('STRELKA_STORED_FILE', 'strelka_bot_shelve.db') TOKEN_FILENAME = os.getenv('STRELKA_TOKEN_FILE', 'token.lst') BALANCE_CHECK_INTERVAL_SEC = 3600 # 1 hour users = {} storer = Storer(STORED_FILE) job_queue = None # Enable Logging logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) logger = logging.getLogger(__name__) def get_description(): return """/help - Show help /getcardbalance - Returns balance for specified card /addcard - Add a card to the list of registered cards /removecard - Remove a card to the list of registered cards /getcards - Returns balance for all registered cards
def __init__(self): self.storer = Storer(db="Quora", collection="user") self.parser = Parser("http://www.quora.com/profile/")