forked from kajweb/wqxuetang_downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
41 lines (34 loc) · 1003 Bytes
/
utils.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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import configparser
import urllib.request
import os
import requests
import logging
def getConf():
confFile = "conf.ini";
conf = configparser.ConfigParser();
conf.read( confFile );
return conf;
def initUrllibNoCookies():
opener = urllib.request.build_opener()
headers=("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36 OPR/65.0.3467.78")
opener.addheaders=[headers]
urllib.request.install_opener(opener)
set_value("urllib",urllib);
def mkdir( folder ):
isExists = os.path.exists(folder)
if not isExists:
os.makedirs( folder, 0o777 );
return True;
return False;
def globalvar_init():
global _global_dict
_global_dict = {}
def set_value(name, value):
_global_dict[name] = value
def get_value(name, defValue=None):
try:
return _global_dict[name]
except KeyError:
return defValue