mirror of
https://github.com/myned/modufur.git
synced 2024-11-01 21:02:38 +00:00
Changed session pool to be active only when needed
(issues arose with a globally active session)
This commit is contained in:
parent
00eec657da
commit
cecd1f3abc
1 changed files with 19 additions and 16 deletions
|
@ -2,31 +2,39 @@ import asyncio
|
|||
import json
|
||||
import os
|
||||
import pickle as pkl
|
||||
import subprocess
|
||||
|
||||
import aiohttp as aio
|
||||
import aiohttp
|
||||
from pync import Notifier
|
||||
|
||||
print('\nPID : {}\n'.format(os.getpid()))
|
||||
|
||||
|
||||
# def notify(message):
|
||||
# subprocess.run(['terminal-notifier', '-message', message, '-title',
|
||||
# 'Modumind', '-activate', 'com.apple.Terminal', '-appIcon', 'icon.png', '-sound', 'Ping'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
print('PID {}'.format(os.getpid()))
|
||||
|
||||
try:
|
||||
with open('config.json') as infile:
|
||||
config = json.load(infile)
|
||||
print('\"config.json\" loaded.')
|
||||
print('config.json loaded.')
|
||||
except FileNotFoundError:
|
||||
with open('config.json', 'w') as outfile:
|
||||
json.dump({'client_id': 0, 'listed_ids': [0], 'owner_id': 0, 'permissions': 126016, 'prefix': ',',
|
||||
'shutdown_channel': 0, 'startup_channel': 0, 'token': 'str'}, outfile, indent=4, sort_keys=True)
|
||||
raise FileNotFoundError(
|
||||
'Config file not found: \"config.json\" created with abstract values. Restart \"run.py\" with correct values.')
|
||||
'Config file not found: config.json created with abstract values. Restart run.py with correct values.')
|
||||
|
||||
|
||||
def setdefault(filename, default=None):
|
||||
try:
|
||||
with open(filename, 'rb') as infile:
|
||||
print('\"{}\" loaded.'.format(filename))
|
||||
print('{} loaded.'.format(filename))
|
||||
return pkl.load(infile)
|
||||
except FileNotFoundError:
|
||||
with open(filename, 'wb+') as iofile:
|
||||
print('File not found: \"{}\" created and loaded with default values.'.format(filename))
|
||||
print('File not found: {} created and loaded with default values.'.format(filename))
|
||||
pkl.dump(default, iofile)
|
||||
iofile.seek(0)
|
||||
return pkl.load(iofile)
|
||||
|
@ -61,14 +69,9 @@ async def clear(obj, interval=10 * 60, replace=None):
|
|||
asyncio.sleep(interval)
|
||||
|
||||
|
||||
session = None
|
||||
|
||||
HEADERS = {'user-agent': 'Modumind/0.0.1 (Myned)'}
|
||||
|
||||
|
||||
async def fetch(url, *, params={}, json=False):
|
||||
global session, HEADERS
|
||||
async with session.get(url, params=params, headers=HEADERS) as r:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url, params=params, headers={'user-agent': 'Modumind/0.0.1 (Myned)'}) as r:
|
||||
if json is True:
|
||||
return await r.json()
|
||||
return r
|
||||
|
|
Loading…
Reference in a new issue