-
Notifications
You must be signed in to change notification settings - Fork 238
/
manage.py
72 lines (63 loc) · 2.15 KB
/
manage.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
# coding:utf-8
#!/usr/bin/env python
import os
import sys
import pymysql
import contextlib
import configparser
cfg = configparser.ConfigParser()
cfg.read('config.ini')
host = cfg.get("Server", "host")
username = cfg.get("Server", "username")
password = cfg.get("Server", "password")
Dbname = cfg.get("Server","dbname").lower()
port = int(cfg.get("Server","port"))
@contextlib.contextmanager
def co_mysql(db='mysql'):
conn = pymysql.connect(host=host,user=username,password=password,port=port,db=db,charset='utf8')
cursor = conn.cursor()
try:
yield cursor
finally:
conn.commit()
cursor.close()
conn.close()
with co_mysql(db='mysql') as cursor:
row_count = cursor.execute("show databases;")
a = cursor.fetchall()
b = [y for x in a for y in x]
if Dbname.lower() in b:
pass
else:
cursor.execute('create database {} DEFAULT CHARSET=utf8mb4'.format(Dbname))
cursor.execute("SET @@global.sql_mode= '';")
cursor.execute("ALTER DATABASE {} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;".format(Dbname))
if __name__ == '__main__':
import multiprocessing
multiprocessing.freeze_support()
if os.path.exists('report'):
pass
else:
os.mkdir('report')
if sys.argv[1] == 'initial':
from initialize.initialdomains import initialdomains
initialdomains()
elif sys.argv[1] == 'startscan':
from core.Run_Tasks import start
start()
elif sys.argv[1] == 'inserturl':
from initialize.initialdomains import InsertUrls
filetxt = sys.argv[2]
if os.path.exists(filetxt):
InsertUrls(filetxt)
else:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'LangSrcCurise.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)