Exemplo n.º 1
0
    def update_groups(self):
        self.driver.get(group_list_url)
        links = self.driver.find_elements_by_xpath(
            "//div[@id='objects_container']//a")
        changes = False
        ids = set()
        for link in links[1:]:  # first is "Create a new group"
            group_id = link.get_attribute("href").split('/')[-1].split('?')[0]
            ids.add(group_id)
            group_name = link.text

            if not group_id in self.db["groups"]:
                self.db["groups"][group_id] = {
                    "subscribers": [db.table("sensitive")["email"]],
                    "name": group_name,
                    "label": group_name,
                    "priority": 0
                }
                changes = True
                self.log("===", group_id, "===")
                self.log("name:", group_name)
        ids_to_remove = set(self.db["groups"].keys()) - ids
        for iid in ids_to_remove:
            del self.db["groups"][iid]
            changes = True
            self.log("===", iid, "===")
            self.log("removed")

        if changes:
            self.db.commit()
Exemplo n.º 2
0
Arquivo: xmat.py Projeto: jarys/xmat
    def loop(self):
        '''Hlavní smyčka.'''
        self.log('load settings')
        self.settings = db.table(self.name + "-settings")

        self.log('start loop')
        self.looping = True
        self.init()

        while self.looping:
            start = time.time()
            timestamp = str(datetime.now())[:-10]
            self.log('start update at {}'.format(timestamp))

            if self.hello_email:
                if time.time() - self.last_hello >= self.hello_period:
                    self.send(self.hello_email,
                              '[{}]: běžím'.format(self.name),
                              'S pozdravem\n' + self.name)
                    self.last_hello = time.time()

            self.update()

            self.log('end update at {}'.format(timestamp))
            try:
                while (time.time() - start <
                       self.waiting_time) and self.looping:
                    time.sleep(3)
            except KeyboardInterrupt:
                self.log('interruption')
                self.stop()

        self.outit()
        self.log('end loop')
Exemplo n.º 3
0
	def __init__(self,name):
		super().__init__(name)
		self.db = db.table(name)

		if 'ids' not in self.db:
			self.db["ids"] = []

		self.target_email = db.load_or_write("sensitive", "email")
Exemplo n.º 4
0
 def __init__(self):
     super().__init__('fbmat', hello_period=4 * 24 * 60 * 60)
     options = selenium.webdriver.firefox.options.Options()
     #options.headless = True
     cap = DesiredCapabilities().FIREFOX
     #cap["marionette"] = False
     self.driver = selenium.webdriver.Firefox(options=options,
                                              capabilities=cap)
     self.db = db.table("fbmat")
Exemplo n.º 5
0
def params():
    message = request.form['post']
    tokens = request.form['token']
    grupos = request.form['grupos']
    usuarios = users(tokens)
    groups = IDgroups(grupos)
    result = table()
    if len(groups) >= 1 and len(usuarios) >= 1 and len(message) != 0:
        ite_groups(groups, message, usuarios)
        insert(groups, usuarios, message)
        valor1 = 'parametros enviados'
    else:
        valor1 = 'faltan parametros'
    return render_template('index.html',
                           valor1=valor1,
                           result=result,
                           formulario=formulario)
Exemplo n.º 6
0
from threading import Thread
from bazosmat import Bazosmat
from sbazarmat import Sbazarmat
import db
import time

bazars = []
for url in db.table("bazarmat")["bazos"]:
    bazar = Bazosmat(url)
    bazars.append(bazar)

for url in db.table("bazarmat")["sbazar"]:
    bazar = Sbazarmat(url)
    bazars.append(bazar)

for bazar in bazars:
    Thread(target=bazar.loop).start()
    time.sleep(2)

running = True
try:
    while running:
        time.sleep(1)
except KeyboardInterrupt:
    running = False

for bazar in bazars:
    bazar.stop()
Exemplo n.º 7
0
def cmd(args):
    '''
	Main function in shell to launch process:
	if --download: take the config settings: execute [download, clean, init, insert, stats]
	if no arguments: execute [init, insert, stats]   
	'''
    ### STEPS/STEP: init and populate db

    logger.info(args)
    status = True
    msg = ""
    ## STEPS is True: create the steps: [init, insert]
    if args.steps is True:
        logger.info("STEPS option is activated: execute only the steps")
        ## STEPS is True and download is False: create the steps: [init, insert]
        ## from files/clean
        if args.download is not False:
            logger.info("with --download")
            # logger.info("- arguments {}".format(args))
            logger.info("create_steps(): download, clean, init, insert")
            status, msg = create_steps()
            return status, msg
        else:
            logger.info("create_steps(): init, insert")
            logger.info(
                "create_steps(): init from files in {}, insert from files in {}"
                .format(args.dirs["ref"], args.dirs["to"]))
            logger.info("remove download and clean")
            steps = STEPS
            # removed_steps = ["download"]
            removed_steps = ["download", "clean"]
            for del_s in removed_steps:
                steps.remove(del_s)
            for step in steps:
                status, msg = create_step(step)
                if status is False:
                    logger.critical("STEP {}() is {}. {}".format(
                        step, status, msg))
                    break
            return status, msg
    # STEP: specify the step between 'download,clean,init,insert' accept multiple steps coma separated
    elif args.step is not None:
        logger.info(
            "STEP option is activated: execute only the steps mentionned")
        for step in args.step.split(","):
            logger.info("STEP {}()".format(args.step))
            status, msg = create_step(step.strip())
            if status is False:
                logger.critical("STEP {}() is {}. {}".format(
                    step, status, msg))
                break
        return status, msg

    ### STATS : generate stats
    elif args.stats in ["create", "delete", "update"]:
        logger.info("STATS option is activated: only {} all stats".format(
            args.stats))
        logger.info("STATS stats({},{})".format(args.stats, args.student))
        if args.stats == "create":
            status, msg = stats(args.stats, args.student)
        elif args.stats == "delete":
            status, msg = stats(args.stats, args.student)
        else:
            #update
            stats("delete", args.student)
            status, msg = stats("create", args.student)
        return status, msg
    # STAT: specify the stat between 'activity, tasks, skills, progression' multiple stats accepted coma separated
    elif args.stat is not None:
        logger.info(
            "STAT option is activated. Only create specified stats {}".format(
                args.stats))
        for stat_name in args.stat.split(","):
            logger.info("STAT {}({})".format(stat_name.strip(), args.student))
            stat(stat_name, action="create", student=args.student)
        return status, msg
    ### TABLES: generate TABLES for STATS create delete or update
    elif args.tables in ["create", "delete", "update"]:
        logger.info("TABLES option is activated. {} all the tables".format(
            args.tables))
        status, msg = tables(action=args.tables, student=args.student)
        return status, msg
    #TABLE specify the table between 'day,chapter,lesson,...', multiple tables accepteds  coma sperated
    elif args.table is not None:
        logger.info(
            "TABLE option is activated. Create only the table: {}".format(
                args.table))
        table_names = args.table.split(",")
        for tablename in table_names:
            logger.info("TABLE({},{}) option is activated".format(
                tablename.strip(), args.student))
            status, msg = table(tablename,
                                action="create",
                                student=args.student,
                                required_table=None)
        return status, msg

    ### COMPLETE SCRIPT
    elif args.download is not False:
        logger.info(
            "Complete execution with download: download, clean, init, insert, stats"
        )
        create_steps()
        status, msg = stats("create", args.student)
        return satus, msg
    else:
        steps = STEPS
        logger.info("No arguments in cmd: falling back to settinngs.json")
        if config["FILES_SERVER"]["activate"] is False:
            # raw directory provided by user

            raw_data_dir = config["FILES_SERVER"]["dir"]

            # if raw_directory provided by user doesn't exists
            if not dir_exists(raw_data_dir) or dir_empty(raw_data_dir):
                # fall back to default CLEAN_DIR
                if not dir_exists(CLEAN_DIR) or dir_empty(CLEAN_DIR):
                    # trying to get default RAW_DIR
                    if not dir_exists(RAW_DIR) or dir_empty(RAW_DIR):
                        msg = "No download option activated and no data found in both provided dir: {} and RAW dir: {}".format(
                            raw_data_dir, RAW_DIR)
                        logger.critical(msg)
                        return False, msg
                    else:
                        steps.remove("download")
                else:
                    steps.remove("download")
                    steps.remove("clean")
            else:
                RAW_DIR = raw_data_dir
                steps.remove("download")
                if not dir_exists(CLEAN_DIR):
                    os.makedirs(CLEAN_DIR)
        logger.info("Execute: {}".format(", ".join(steps)))
        create_steps(steps)
        status, msg = stats("create", args.student)
        return status, msg
Exemplo n.º 8
0
 def __init__(self):
     super().__init__('kotmat')
     self.db = db.table("kotmat")
Exemplo n.º 9
0
	def __init__(self):
		super().__init__('espolubydleni')
		self.db = db.table("espolubydleni")
Exemplo n.º 10
0
def index():
    result = table()
    return render_template('index.html', result=result, formulario=formulario)
Exemplo n.º 11
0
def get_page_name(site, page):
    db = TinyDB(f'''blogs/{site}.json''')
    page = db.table('pages').get(doc_id=int(page))
    return page['title']
Exemplo n.º 12
0
def get_posts(site, page):
    db = TinyDB(f'''blogs/{site}.json''')
    Posts = Query()
    return db.table('posts').search(Posts.page_id == page)
Exemplo n.º 13
0
def get_pages(site):
    db = TinyDB(f'''blogs/{site}.json''')
    return db.table('pages').all()