def take_action(self, parsed_args): if not parsed_args.update: self.app.stdout.write('%s\n' % config.get('Domain', '<<Domain not set!>>')) return config['Domain'] = parsed_args.update config.save()
def __init__(self, bot): self.bot = bot self.embed_color = 0xffd663 self.PremiumHandler = premiumhandler.PremiumHandler() # Module configuration self.module_name = str(self.__class__.__name__) self.is_restricted_module = True self.module_dependencies = [] qulib.module_configuration(self.module_name, self.is_restricted_module, self.module_dependencies) # Main Config.ini Configuration if 'Premium' not in config.sections(): config.add_section('Premium') config.set('Premium', 'WebhookAuth', '<Enter Patreon webhook secret here>') with open(os.path.join(bot_path, 'config.ini'), 'w', encoding="utf_8") as config_file: config.write(config_file) config_file.close() with open(os.path.join(bot_path, 'config.ini'), 'r', encoding="utf_8") as config_file: config.read_file(config_file) self.patreon_auth = config.get('Premium', 'WebhookAuth') config_file.close() self.webhook_task = self.bot.loop.create_task(self.webhook()) # Starting module-related tasks self.expired_premium_subscriptions.start() # pylint: disable=no-member print(f'Module {self.__class__.__name__} loaded')
async def main(): osm = OsmApi(username=config.get("OSM_SUBMIT_USER"), password=config.get("OSM_SUBMIT_PASSWORD")) print("Connecting...") await database.connect() print("Updating materialised view...") await database.execute("REFRESH MATERIALIZED VIEW CONCURRENTLY solartag.candidates") print("Fetching changes...") while True: res = await database.fetch_all("""SELECT results.osm_id, array_agg(results.user_id) AS users, solartag.int_decision_value(module_count) AS modules FROM solartag.results, solartag.candidates WHERE results.osm_id = candidates.osm_id GROUP BY results.osm_id HAVING solartag.int_decision(module_count) = true AND solartag.int_decision_value(module_count) IS NOT NULL ORDER BY results.osm_id DESC LIMIT 100""") users = set() for row in res: users |= set(row['users']) if len(list(res)) < 10: print("Fewer than 10 new changes, not submitting.") return print(f"Submitting changeset of {len(list(res))} objects...") print("Creating changeset...") osm.ChangesetCreate({"contributor_ids": ";".join(map(str, users)), "source": "https://solartagger.russss.dev", "comment": "Add generator:solar:modules tag", "bot": "yes", "imagery_used": "Bing" }) for row in res: node = osm.NodeGet(row['osm_id']) if 'generator:solar:modules' in node['tag']: print("Tag already exists for node", node['id']) continue node['tag']['generator:solar:modules'] = str(row['modules']) osm.NodeUpdate(node) osm.ChangesetClose() print("Done")
def __init__(self, bot): self.bot = bot self.embed_color = 0x28b463 # Module configuration self.module_name = str(self.__class__.__name__) self.is_restricted_module = False self.module_dependencies = [] qulib.module_configuration(self.module_name, self.is_restricted_module, self.module_dependencies) qulib.user_database_init() self.GiveawayHandler = GiveawayHandler() if 'Economy' not in config.sections(): config.add_section('Economy') if 'CurrencySymbol' not in config['Economy']: config.set('Economy', 'CurrencySymbol', '💵') if 'DailyAmount' not in config['Economy']: config.set('Economy', 'DailyAmount', '100') with open(os.path.join(bot_path, 'config.ini'), 'w', encoding="utf_8") as config_file: config.write(config_file) config_file.close() with open(os.path.join(bot_path, 'config.ini'), 'r', encoding="utf_8") as config_file: config.read_file(config_file) self.daily_amount = int(config.get('Economy', 'DailyAmount')) self.vote_reward = int( int(config.get('Economy', 'DailyAmount')) / 2) self.currency_symbol = config.get('Economy', 'CurrencySymbol') config_file.close() print(f'Module {self.__class__.__name__} loaded')
from typing import Dict, List import psycopg2 from logging_seting import logger from main import config name = config.get('Postgresql', 'db') user = config.get('Postgresql', 'user') password = config.get('Postgresql', 'password') host = config.get('Postgresql', 'host') conn = psycopg2.connect(database=name, user=user, password=password, host=host, port=5432) logger.info('Postgresql database opened succsesfuly') cursor = conn.cursor() def insert(values: Dict) -> None: cursor.execute( "INSERT INTO screenshot(name, url, customer) " f"VALUES('{values['name']}', '{values['url']}', '{values['user']}');") conn.commit() def delete(row_name: str) -> None: cursor.execute(f"DELETE FROM screenshot WHERE name = '{row_name}';") conn.commit() def fetchall(user: str) -> List[Dict]:
from main import config import pymongo from pymongo import MongoClient from mongo.crud import MongoCRUD # 数据库前缀 DB_PREFIX = config.get("sys").get("db_prefix") mdb = MongoClient(**config.get("sys").get("mongoDb")) def get_db(module): return mdb[DB_PREFIX + module] CRUD = MongoCRUD
from main import app, config if __name__ == '__main__': host = config.get('host') port = int(config.get('port')) app.run(debug=False, host=host, port=port)
import logging import os from main import config log_path = config.get("sys").get("log_path") from main.utils.time import getToday_s class FileLog(): loggers = {} debugger = True # debugger=False def __init__(self, name, sub_path=".", level=logging.INFO, today=False, formatter="'%(asctime)s:%(levelname)s:%(message)s"): self.name = os.path.splitext(name)[0] + "_" + getToday_s( ) + os.path.splitext(name)[1] if today else name self.path = os.path.join(os.getcwd(), log_path, sub_path) self.level = level if self.debugger: self.level = logging.DEBUG self.formatter = formatter self.sub_path_name = os.path.join(sub_path, self.name) self.init_log() def init_log(self): self.logger = self.loggers.get(self.sub_path_name) if not self.logger: