This repository has been archived by the owner on Dec 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
base.py
75 lines (59 loc) · 1.81 KB
/
base.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
75
# -*- coding: utf-8 -*-
# -------------------------------------------
# nobo, No Borders
#
# fixja.py
# A collection of useful basic functions.
# -------------------------------------------
# @Author : Zhou Fang
# @Updated : 1/28/2019
# @Homepage: https://github.com/fang2hou/nobo
# -------------------------------------------
import os
import sys
import json
import hashlib
DEBUG = True
def load_config(path=None):
"""
Load configuration from file.
The configuration should be a valid JSON file.
If the path is empty, Nobo will load default configuration.
Args:
path: the location that configuration file is.
Returns:
A dict mapping keys to the corresponding table row data fetched.
"""
default_config = {
"basic":{
"local_cache_dir": "localdb"
},
"manaba": {
"homepage": "https://ct.ritsumei.ac.jp/ct/home",
"domain_root": "ct.ritsumei.ac.jp",
"login_domain_root": "sso.ritsumei.ac.jp",
"login_attempt_interval": 0.5,
"timeout": 10,
"cookies_cache": True,
"encryption": "md5",
"save_mode": "file"
}
}
if None != path:
with open(path, 'r') as configuration:
return json.loads(configuration.read())
return default_config
def LoadCookiesFromFile(cacheDirectory, fileId):
if not os.path.isdir(cacheDirectory + "/cookies/"):
os.makedirs(cacheDirectory + "/cookies/")
try:
with open(cacheDirectory + "/cookies/" + fileId, 'r+') as f:
return json.loads(f.read())
except FileNotFoundError:
return None
def convert_to_md5(str):
hashlib.md5().update(str.encode("utf8"))
return hashlib.md5().hexdigest()
def debug_print(str):
if DEBUG:
print(str)