コード例 #1
0
    def mabyDoPasswordAndLogins(self, screen):
        if Config.getboolean("Misc", "saveLogins"):
            screen.ids["UsrNameInput"].text = Config.get("Misc", "username")
            screen.ids["PwdInput"].text = decode(
                str(Config.get("Misc", "password")), "JonIsGreen")

            Logger.info("Logins: Loaded")
コード例 #2
0
ファイル: configItem.py プロジェクト: GreenJon902/MemriseBot
    def update(self, *args):
        self.ids["Title"].text = self.title
        self.ids["Description"].text = self.description

        self._editorHolder.clear_widgets()

        if self.type == "numericSlider":
            if self.sliderMin is None or self.sliderMax is None:
                raise ValueError("'sliderMin' and / or 'sliderMax' cannot be 'None' if type is numericSlider")


            self._editorWidget = Slider(min=self.sliderMin, max=self.sliderMax,
                                        value=Config.getint(self.section, self.option), step=1)
            self._editorWidget.bind(value=self.value_changed)

            self._editorWidget2 = TextInput(multiline=False, font_size=self._editorHolder.height / 2,
                                            text=Config.get(self.section, self.option), input_filter="int")
            self._editorWidget2.bind(on_text_validate=self.text_box_int_validator)
            self._editorWidget2.bind(focus=self.text_box_int_validator)


        elif self.type == "bool":
            self._editorWidget = Switch(active=Config.getboolean(self.section, self.option))
            self._editorWidget.bind(active=self.value_changed)


        elif self.type == "string":
            self._editorWidget = TextInput(multiline=False, font_size=self._editorHolder.height / 2,
                                           text=Config.get(self.section, self.option))
            self._editorWidget.bind(on_text_validate=lambda *args: self.value_changed(None, self._editorWidget.text))
            self._editorWidget.bind(focus=lambda *args: self.value_changed(None, self._editorWidget.text))

        elif self.type == "option":
            self._editorWidget = Button(text=Config.get(self.section, self.option))

            dropDown = DropDown()

            for option in self.options:
                text = str(option)
                try:
                    text = text + " - " + str(self.extra_info[option])
                except KeyError:
                    pass

                btn = Button(text=text, size_hint_y=None, height=self.height)
                btn.tag = str(option)
                btn.bind(on_release=lambda _btn: dropDown.select(_btn.tag))
                dropDown.add_widget(btn)

            self._editorWidget.bind(on_release=dropDown.open)
            self._editorWidget.bind(on_release=lambda *args: emptyFunction(dropDown.children))
            dropDown.bind(on_select=lambda instance, x: setattr(self._editorWidget, 'text', x))
            dropDown.bind(on_select=self.value_changed)


        if self._editorWidget2 is not None:
            self._editorHolder.add_widget(self._editorWidget2)

        if self.type != "title":
            self._editorHolder.add_widget(self._editorWidget)
コード例 #3
0
    def on_stop(self):
        Config.write()

        mining = self.root.get_screen("MiningScreen")

        try:
            mining.Miner.driver.quit()
        except AttributeError:
            pass
コード例 #4
0
ファイル: configItem.py プロジェクト: GreenJon902/MemriseBot
    def value_changed(self, _, value):
        if self._editorWidget2 is not None:
            self._editorWidget2.text = str(value)

            self._editorWidget.value = int(value)

        Logger.info("Config: " + self.section + self.option + " set to " + str(value))
        Config.set(self.section, self.option, value)
        Config.write()
        Logger.info("Config: Saved config")
コード例 #5
0
    def __oauth_process_token_request(self, req):
        success = False

        if req.status_code == 200:
            # Success; saving the access token
            access_token_response = req.json()
            access_token = access_token_response['access_token']

            # But first we need to find out what user this token belongs to
            temp_headers = self._headers_without_authentication()
            temp_headers['Authorization'] = 'Bearer ' + access_token

            req = requests.get('https://api.trakt.tv/users/me',
                               headers=temp_headers)

            from misc.config import Config
            new_config = Config()

            new_config.merge_settings(
                {"trakt": {
                    req.json()['username']: access_token_response
                }})

            success = True
        elif req.status_code == 404:
            log.debug('The device code was wrong')
            log.error(
                'Whoops, something went wrong; aborting the authentication process'
            )
        elif req.status_code == 409:
            log.error(
                'You\'ve already authenticated this application; aborting the authentication process'
            )
        elif req.status_code == 410:
            log.error(
                'The authentication process has expired; please start again')
        elif req.status_code == 418:
            log.error(
                'You\'ve denied the authentication; are you sure? Please try again'
            )
        elif req.status_code == 429:
            log.debug('We\'re polling too quickly.')

        return success, req.status_code
コード例 #6
0
    def __init__(self, config: str):
        self.logger = colorlog.getLogger(self.__class__.__name__)
        signal.signal(signal.SIGINT, self.shutdown)
        signal.signal(signal.SIGTERM, self.shutdown)
        self.config = Config(args.config)
        self.db = DB(self.config)

        i2c = busio.I2C(board.SCL, board.SDA)
        self.sensors = [BME680(i2c, self.config), SGP30(i2c, self.config)]
        self.alive = True
        pass
コード例 #7
0
        def start(self):
            self.webpage_image_update_interval = Config.getfloat(
                "Gui", "webpage_image_update_interval")

            self.install_dependants()
            self.setup()
            self.start_webpage_image_updater()
            self.do_webpage_image_update = True
            self.pre_mine()
            self.mine()
            self.do_webpage_image_update = False
            self.post_mine()
コード例 #8
0
        def setup(self):
            try:
                self.driver.quit()
            except AttributeError:
                pass

            chromedriver_autoinstaller.install()
            Logger.info("Miner: Chromedriver installed if not already")

            chrome_options = ChromeOptions()
            if Config.getboolean("Gui", "headless"):
                chrome_options.add_argument("--headless")
            chrome_options.add_argument("--window-size=1920,1080")
            chrome_options.add_argument(
                "--log-path=" +
                str(os.path.join(user_data_dir, "chromedriver.log")))
            Logger.info("Miner: Chromedriver setup")

            url = Config.get("URLs", "sign_in")
            self.driver = webdriver.Chrome(options=chrome_options)
            self.driver.get(url)

            Logger.info("Miner: Loaded " + str(url))
コード例 #9
0
        def pre_mine(self):
            Logger.info("Miner: Started pre mining setup function")

            MemriseElements.get("username_input",
                                self.driver).send_keys(self.usrName)
            MemriseElements.get("password_input",
                                self.driver).send_keys(self.pwdInput)
            MemriseElements.get("login_submit_button", self.driver).click()

            wait_till_page_load(self.driver)

            home_courses_elements = MemriseElements.get_multiple(
                "courses", self.driver)
            home_courses = {}
            for course in home_courses_elements:
                home_courses[str(MemriseElements.get("course_title", course).get_attribute("title"))] = \
                    MemriseElements.get("course_title", course).find_element(By.TAG_NAME, "a").get_attribute("href")
            Logger.info("Miner: Located courses and links: \n" +
                        str(pformat(home_courses)))

            self.driver.get(Config.get("URLs", "groups"))

            groups_elements = MemriseElements.get_multiple(
                "groups_individual",
                MemriseElements.get("groups", self.driver))
            groups_courses = {}
            for group in groups_elements:
                groups_courses[str(
                    MemriseElements.get("groups_individual_title",
                                        group).text)] = {}
                for course in MemriseElements.get_multiple(
                        "groups_individual_courses", group):

                    groups_courses[str(
                        MemriseElements.get(
                            "groups_individual_title",
                            group).text)][MemriseElements.get(
                                "course_title",
                                course).text] = MemriseElements.get(
                                    "course_title", course).find_element(
                                        By.TAG_NAME, "a").get_attribute("href")

            Logger.info("Miner: Located groups, courses and links: \n" +
                        str(pformat(groups_courses)))

            Logger.info("Miner: Finished pre mining setup function")
コード例 #10
0
ファイル: traktarr.py プロジェクト: hongkongkiwi/traktarr
def app(config, logfile):
    # Setup global variables
    global cfg, log, notify

    # Load config
    from misc.config import Config
    cfg = Config(config_path=config, logfile=logfile).cfg

    # Load logger
    from misc.log import logger
    log = logger.get_logger('traktarr')

    # Load notifications
    from notifications import Notifications
    notify = Notifications()

    # Notifications
    init_notifications()
コード例 #11
0
    def start_mining(self):
        home = self.root.get_screen("HomeScreen")

        if Config.getboolean("Misc", "saveLogins"):
            Config.set("Misc", "username", home.ids["UsrNameInput"].text)
            Config.set("Misc", "password",
                       encode(str(home.ids["PwdInput"].text), "JonIsGreen"))
            Config.write()

            Logger.info("Logins: Saved")

        Miner = self.root.get_screen("MiningScreen").Miner
        Miner.usrName = home.ids["UsrNameInput"].text
        Miner.pwdInput = home.ids["PwdInput"].text
        Miner.stopOnlyWhenStopPressed = home.ids["MineUntilOrForSwitch"].active
        Miner.mineUntilPoints = None if home.ids[
            "PointsInput"].text == "" else home.ids["PointsInput"].text
        Miner.mineForTime = None if home.ids[
            "TimeInput"].text == "" else home.ids["TimeInput"].text
        Miner.requireAll = home.ids["RequirementsAll"].state == "down"

        self.root.current = "MiningScreen"
コード例 #12
0
def wait_till_page_load(driver, timeout=Config.getint("Mining", "page_timeout")):
    Logger.info("WebDriverWait: Starting")
    driver.implicitly_wait(timeout)
    Logger.info("WebDriverWait: Finished")
コード例 #13
0
import json
import time

import backoff
import requests
from cashier import cache

from helpers.misc import backoff_handler, dict_merge
from helpers.trakt import extract_list_user_and_key_from_url
from misc.log import logger
from misc.config import Config

log = logger.get_logger(__name__)
cachefile = Config().cachefile


class Trakt:
    non_user_lists = [
        'anticipated', 'trending', 'popular', 'boxoffice', 'watched', 'played'
    ]

    def __init__(self, cfg):
        self.cfg = cfg

    ############################################################
    # Requests
    ############################################################

    def _make_request(self,
                      url,
                      payload=None,
コード例 #14
0
# from InceptionScore import calculate_inception_score

# from misc.losses import sent_loss, words_loss, sent_triplet_loss, words_triplet_loss

from torch.utils.tensorboard import SummaryWriter
# from torch.utils.data import DataLoader

import math
from tqdm import tqdm
import timeit
# from catr.engine import train_one_epoch, evaluate
from misc.config import Config
# from transformers import BertConfig,BertTokenizer
# from nltk.tokenize import RegexpTokenizer

cfg = Config()


# ################# Joint Image Text Representation (JoImTeR) learning task############################ #
class JoImTeR(object):
    def __init__(self, output_dir, data_loader, dataloader_val):
        if cfg.TRAIN:
            self.model_dir = os.path.join(output_dir, 'Model')
            self.image_dir = os.path.join(output_dir, 'Image')
            mkdir_p(self.model_dir)
            mkdir_p(self.image_dir)

        torch.cuda.set_device(cfg.GPU_ID)
        cudnn.benchmark = True
        Q_c = np.array([46, 53, 86, 103, 137, 265, 290, 2422])
        Q = 3166.0
コード例 #15
0
    class _Miner(EventDispatcher):
        usrName = StringProperty("")
        pwdInput = StringProperty("")
        stopOnlyWhenStopPressed = BooleanProperty(False)
        mineUntilPoints = NumericProperty(None)
        mineForTime = NumericProperty(None)
        requireAll = BooleanProperty(True)
        midLinePos = NumericProperty(0)
        webpage_image_update_interval = Config.getfloat(
            "Gui", "webpage_image_update_interval")

        do_webpage_image_update = False
        driver = None
        Gui = None

        def start(self):
            self.webpage_image_update_interval = Config.getfloat(
                "Gui", "webpage_image_update_interval")

            self.install_dependants()
            self.setup()
            self.start_webpage_image_updater()
            self.do_webpage_image_update = True
            self.pre_mine()
            self.mine()
            self.do_webpage_image_update = False
            self.post_mine()

        def start_webpage_image_updater(self):
            Thread(target=self.webpage_image_updater, daemon=True).start()

        def webpage_image_updater(self):
            while True:
                if self.do_webpage_image_update:
                    t = time.time()

                    Logger.debug("WebpageImage: Starting image update")

                    data = io.BytesIO(self.driver.get_screenshot_as_png())

                    coreImage = CoreImage(data, ext="png")
                    Clock.schedule_once(
                        lambda _: self.Gui.update_webpage_image(coreImage, t),
                        0)

                    try:
                        time.sleep(self.webpage_image_update_interval -
                                   (time.time() - t))
                    except ValueError:
                        Logger.warning(
                            "WebpageImage: Convert took to long, took " +
                            str(time.time() - t) + " and it should've took " +
                            str(self.webpage_image_update_interval))

                else:
                    time.sleep(self.webpage_image_update_interval)

        def install_dependants(self):
            chromedriver_autoinstaller.install()
            Logger.info("Miner: Chromedriver installed if not already")

        def setup(self):
            try:
                self.driver.quit()
            except AttributeError:
                pass

            chromedriver_autoinstaller.install()
            Logger.info("Miner: Chromedriver installed if not already")

            chrome_options = ChromeOptions()
            if Config.getboolean("Gui", "headless"):
                chrome_options.add_argument("--headless")
            chrome_options.add_argument("--window-size=1920,1080")
            chrome_options.add_argument(
                "--log-path=" +
                str(os.path.join(user_data_dir, "chromedriver.log")))
            Logger.info("Miner: Chromedriver setup")

            url = Config.get("URLs", "sign_in")
            self.driver = webdriver.Chrome(options=chrome_options)
            self.driver.get(url)

            Logger.info("Miner: Loaded " + str(url))

        def pre_mine(self):
            Logger.info("Miner: Started pre mining setup function")

            MemriseElements.get("username_input",
                                self.driver).send_keys(self.usrName)
            MemriseElements.get("password_input",
                                self.driver).send_keys(self.pwdInput)
            MemriseElements.get("login_submit_button", self.driver).click()

            wait_till_page_load(self.driver)

            home_courses_elements = MemriseElements.get_multiple(
                "courses", self.driver)
            home_courses = {}
            for course in home_courses_elements:
                home_courses[str(MemriseElements.get("course_title", course).get_attribute("title"))] = \
                    MemriseElements.get("course_title", course).find_element(By.TAG_NAME, "a").get_attribute("href")
            Logger.info("Miner: Located courses and links: \n" +
                        str(pformat(home_courses)))

            self.driver.get(Config.get("URLs", "groups"))

            groups_elements = MemriseElements.get_multiple(
                "groups_individual",
                MemriseElements.get("groups", self.driver))
            groups_courses = {}
            for group in groups_elements:
                groups_courses[str(
                    MemriseElements.get("groups_individual_title",
                                        group).text)] = {}
                for course in MemriseElements.get_multiple(
                        "groups_individual_courses", group):

                    groups_courses[str(
                        MemriseElements.get(
                            "groups_individual_title",
                            group).text)][MemriseElements.get(
                                "course_title",
                                course).text] = MemriseElements.get(
                                    "course_title", course).find_element(
                                        By.TAG_NAME, "a").get_attribute("href")

            Logger.info("Miner: Located groups, courses and links: \n" +
                        str(pformat(groups_courses)))

            Logger.info("Miner: Finished pre mining setup function")

        def mine(self):
            Logger.info("Miner: Started mining function")

            pass

            Logger.info("Miner: Finished mining function")

        def post_mine(self):
            self.driver.close()
コード例 #16
0
ファイル: log.py プロジェクト: superhotchili/PGBlitz.com
        # init console_logger
        self.console_handler = logging.StreamHandler(sys.stdout)
        self.console_handler.setFormatter(self.log_formatter)
        self.root_logger.addHandler(self.console_handler)

        # init file_logger
        if file_name:
            if os.path.sep not in file_name:
                # file_name was a filename, lets build a full file_path
                self.log_file_path = os.path.join(
                    os.path.dirname(os.path.realpath(sys.argv[0])), file_name)
            else:
                self.log_file_path = file_name

            self.file_handler = RotatingFileHandler(self.log_file_path,
                                                    maxBytes=1024 * 1024 * 5,
                                                    backupCount=5)
            self.file_handler.setFormatter(self.log_formatter)
            self.root_logger.addHandler(self.file_handler)

        # Set chosen logging level
        self.root_logger.setLevel(log_level)

    def get_logger(self, name):
        return self.root_logger.getChild(name)


# Default logger
logger = Logger(Config().logfile,
                logging.DEBUG if Config().cfg.core.debug else logging.INFO)
コード例 #17
0
ファイル: trainer_v2.py プロジェクト: mshaikh2/IPMI2021
from misc.losses import sent_loss, words_loss, sent_triplet_loss, words_triplet_loss

from torch.utils.tensorboard import SummaryWriter
# from torch.utils.data import DataLoader

import math
from tqdm import tqdm
import timeit
# from catr.engine import train_one_epoch, evaluate
from misc.config import Config
from transformers import BertConfig,BertTokenizer
from nltk.tokenize import RegexpTokenizer


cfg = Config() # initialize catr config here
# tokenizer = BertTokenizer.from_pretrained(cfg.vocab, do_lower=True)
# retokenizer = BertTokenizer.from_pretrained("catr/damsm_vocab.txt", do_lower=True)
# # reg_tokenizer = RegexpTokenizer(r'\w+')
# frozen_list_image_encoder = ['Conv2d_1a_3x3','Conv2d_2a_3x3','Conv2d_2b_3x3','Conv2d_3b_1x1','Conv2d_4a_3x3']

# @torch.no_grad()
# def evaluate(cnn_model, trx_model, cap_model, batch_size, cap_criterion, dataloader_val):
#     cnn_model.eval()
#     trx_model.eval()
#     cap_model.eval() ### 
#     s_total_loss = 0
#     w_total_loss = 0
#     c_total_loss = 0 ###
#     ### add caption criterion here. #####
# #     cap_criterion = torch.nn.CrossEntropyLoss() # add caption criterion here
コード例 #18
0
 def __init__(self):
     self.bot = None
     self.modules = []
     self.config = Config()
コード例 #19
0
import os
import re
import imghdr
import urllib.parse as urlparse
import requests
import time
import hashlib
from datetime import datetime
from PIL import Image
if __name__ == '__main__':
    from crawler.common import DESKTOP_UA
else:
    from .common import DESKTOP_UA
try:
    from misc.config import Config
    parameter = Config().value
except ImportError:
    Config = None
    parameter = {
        'Download': {
            'TimeOut': 10,
            'DownloadBlock': 1024,
            'GUIInterval': 0.1
        }
    }


class DownloadImage(object):
    def __init__(self,
                 url,
                 directory='',
コード例 #20
0
class Bot:
    def __init__(self):
        self.bot = None
        self.modules = []
        self.config = Config()

    async def on_ready(self):
        """Event handler for when the bot is ready."""
        log("Initializing bot presence...")
        game = self.config.get("game-presence", "Skynet")
        await self.bot.change_presence(activity=discord.Game(name=game))

        log("Loading modules...")
        self.modules = [DeckEditModule(self, self.bot)]

        log("Initialization complete, %d modules loaded." % len(self.modules))

    async def on_message_delete(self, msg):
        """Event handler for when a message is deleted.

        Args:
            msg: The message that was deleted.
        """
        for module in self.modules:
            await module.on_message_delete(msg)

    async def on_message_edit(self, before, after):
        """Event handler for when a message is edited.

        Args:
            before: The message before the edit.
            after: The message after the edit.
        """
        for module in self.modules:
            await module.on_message_edit(before, after)

    async def on_member_join(self, member):
        """Event handler for when a member joins the server.

        Args:
            member: The member that joined the server.
        """
        for module in self.modules:
            await module.on_member_join(member)

    async def on_member_remove(self, member):
        """Event handler for when a member leaves the server.

        Args:
            member: The member that left the server.
        """
        for module in self.modules:
            await module.on_member_remove(member)

    async def on_message(self, msg):
        """Event handler for messages.

        Args:
            msg: The message.
        """
        for module in self.modules:
            await module.on_message(msg)

    async def handle_command(self, msg, cmd, args):
        """Event handler for commands.

        Args:
            msg: The message that contains the command.
            cmd: The command.
            args: The arguments provided.
        """
        for module in self.modules:
            await module.on_command(msg, cmd, args)
コード例 #21
0
ファイル: main.py プロジェクト: mshaikh2/IPMI2021
import time
import random
import pprint
import datetime
import dateutil.tz
import argparse
import numpy as np
import pandas as pd
import torch
import torchvision.transforms as transforms
import pickle

dir_path = (os.path.abspath(os.path.join(os.path.realpath(__file__), './.')))
sys.path.append(dir_path)

cfg = Config()


def parse_args():
    parser = argparse.ArgumentParser(description='Train a AttnGAN network')
    parser.add_argument('--gpu', dest='gpu_id', type=int, default=-1)
    parser.add_argument('--data_dir', dest='data_dir', type=str, default='')
    args = parser.parse_args()
    return args


if __name__ == "__main__":
    args = parse_args()

    if args.gpu_id != -1:
        cfg.GPU_ID = args.gpu_id