forked from kaibruneji/MyIrcBot
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
74 lines (60 loc) Β· 2.01 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# main.py
import datetime
# import whois
import json
import socket
import time
import traceback
from random import choice
from threading import Thread
from urllib.parse import quote as urlencode
from urllib.parse import unquote
from urllib.error import URLError
import pytz
import requests
import socks
import subprocess
from pytrends.request import TrendReq
import settings
import translate_krzb
from settings import settings as option
from settings import getconfig
from helpers import get_pretty_json_string, shell
from tgbich import run_tgbich
from ircbich import ircbich_init_and_loop
functions = {'tg': run_tgbich, 'irc': ircbich_init_and_loop}
print(f"{__file__}, {__name__}: starting")
from multiprocessing import Process
import os
print(f"{__file__}, {__name__}: pytrends: processing Trend Requests")
while True:
try:
pytrends = TrendReq(hl='ru-RU', tz=360)
break
except KeyboardInterrupt as e:
raise e
except:
traceback.print_exc()
TIME_TO_SLEEP_SECONDS = 1
print("sleeping %s seconds" % str(TIME_TO_SLEEP_SECONDS))
time.sleep(TIME_TO_SLEEP_SECONDS)
continue
print(f"{__file__}, {__name__}: pytrends: completed.")
# launch processes
def launch_all():
print("processing configs")
cfg = getconfig()
print("processing connections")
connections = cfg["connections"]
for key in connections.keys():
print(f"processing connections.{key}")
section = connections[key]
for section_key in section.keys():
print(f" processing connections.{key}.{section_key}")
conn_props = section[section_key]
print(f" launching connection {key}.{section_key}, conn_props='{conn_props}'")
Process(target=functions[key], args=(key, conn_props, cfg, )).start()
print(f" launched connection {key}.{section_key}")
print(f" processed connections.{key}.{section_key}")
print(f"processed connections.{key}")
print("all launched; processed all connections")