def GetCeps(): try: ##Mock list or get from db listCeps = ['23575210','23510600'] return listCeps except Error as e: logs.Log(f"Error getting ceps - {e}") finally: logs.Log("Finally GetCeps()")
def Start(): now = datetime.now() cepsList = ceps.GetCeps() for cep in cepsList: try: ret = f'CEP: {cep} localizado com sucesso!' endereco = correiosService.ConsultarCepPage(cep) logs.Log(ret) logs.Log(endereco.GetObjectText()) except Exception as e: logs.Log(f'Cep: {cep} Erro: {str(e)}')
def __init__(self, ctx): self.logs = logs.Log() self.ctx = ctx self.crud = crud.Crud() self.discord_id = ctx.author.guild.id self.language = texts.EN() self.league_name = None self.tournament_name = None self.goblin_token = None saved_data = self.crud.recover_config(self.discord_id) if saved_data: self.league_name = saved_data.league_name self.tournament_name = saved_data.tournament_name self.goblin_token = saved_data.goblin_token self.language = dictionaries.get_language(saved_data.language) self.goblin = goblinSpy.GoblinSpy(self.goblin_token, self.crud)
# Derek Santos import argparse import configuration import imgur import imgur_downloader import json import logs from os.path import expanduser, exists, join from sys import platform from traceback import print_exc CONFIG_PATH = join(expanduser('~'), ".config", "imgurToFolder", 'config.json') log = logs.Log('main') def parse_arguments(): """ Parse command line arguments """ parser = argparse.ArgumentParser( description='Download images off Imgur to a folder of your choice!') parser.add_argument('urls', metavar='URLS', type=str, nargs='*', help='Automatically detect urls') parser.add_argument('--folder', '-f', metavar='PATH', type=str, help='Change desired folder path')
import logs from pprint import pformat import re import requests import webbrowser from time import sleep import os log = logs.Log('imgur') class Imgur: def __init__(self, configuration): log.debug('Configuration set') self._configuration = configuration def set_configuration(self, configuration): log.debug('Changed configuration') self._configuration = configuration def set_download_path(self, path): log.debug('Chaning download path') if not os.path.exists(path): os.makedirs(path) self._configuration.set_download_path(path) def set_default_folder_path(self, path): log.debug('Chaning download path') if not os.path.exists(path): os.makedirs(path) self._configuration.set_default_download_path(path)
# Derek Santos from imgur import Imgur from pprint import pformat from time import sleep import json import logs import os import re import requests import shutil from urllib.parse import urlparse log = logs.Log('downloader') class Imgur_Downloader(Imgur): def __init__(self, configuration, max_favorites): super().__init__(configuration) self._max_favorites = max_favorites def replace_characters(self, word): # NOTE: '\\/:*?"<>|.' are invalid folder characters in a file system invalid_characters = [ '\\', "'", '/', ':', '*', '?', '"', '<', '>', '|', '.', '\n' ] for character in invalid_characters: word = word.replace(character, '') word = word.strip()
import json import logs from os import mkdir import os.path log = logs.Log('configuration') class Configuration: def __init__(self, config_path, access_token='', client_id='', client_secret='', download_path='', refresh_token='', overwrite=False): log.debug('Setting configuration') self._config_path = config_path self._access_token = access_token self._client_id = client_id self._client_secret = client_secret self._download_path = os.path.realpath(os.path.expanduser(download_path)) self._refresh_token = refresh_token self._overwrite = overwrite log.debug('Configuration set') def set_access_token(self, token): log.debug('Setting access_token') self._access_token = token self.save_configuration() def set_client_id(self, client_id): log.debug('Setting client_id') self._client_id = client_id self.save_configuration()
#coding utf8 import paramiko, os import logs l = logs.Log() paramiko.util.log_to_file("a.txt", 'ERROR') class ssh_conn(): def __init__(self): self.ssh = paramiko.SSHClient() def ssh2(self, ip, username, pwd, key): try: if key == '': self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) self.ssh.connect(ip, 22, username, pwd, timeout=10) else: key = paramiko.RSAKey.from_private_key_file(key) self.ssh.load_system_host_keys() self.ssh.connect(ip, 22, username, pkey=key, timeout=10) return True except Exception, ex: l.log("CONNECTION", str(ex), 1) return False def close(self): self.ssh.close() def commmad(self, cmd): stdin, stdout, stderr = self.ssh.exec_command(cmd) out = stdout.readlines()
import time import account_info import mention_stream import logs import signal import os authenticate = tweepy.OAuthHandler(account_info.consumer_key, account_info.consumer_secret) authenticate.set_access_token(account_info.access_token, account_info.access_token_secret) api = tweepy.API(authenticate, wait_on_rate_limit=True) postTime = 43 log = logs.Log('out.log') link = link_generator.LinkGenerator(log) myStreamListener = mention_stream.MyStreamListener(api, log, link) myStream = tweepy.Stream(auth=api.auth, listener=myStreamListener) myStream.filter(track=['@' + account_info.account_user_name + " prog"], async=True) def signal_handler(signal, frame): log.printLog("debug", "Keyboard Interrupt.") os._exit(1) def postTweet(api, postTime):
def __init__(self): self.database = sqlite3.connect(os.getenv('SQLITE_CONNECTION')) self.log = logs.Log() self.database.execute("PRAGMA foreign_keys = 1")