logicdn 1.0.395 → 1.0.399

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ import time
5
5
  import json
6
6
  import shutil
7
7
  import random
8
+ import subprocess
8
9
  from datetime import datetime
9
10
  from urllib.parse import urlsplit
10
11
  from concurrent.futures import ThreadPoolExecutor
@@ -14,30 +15,48 @@ from PIL import Image
14
15
 
15
16
  TIME_OUT = 20
16
17
  MAX_TRY = 3
18
+ POOL_SIZE = 7
19
+ PROXY = 'http://127.0.0.1:8888'
17
20
  USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36'
18
- WHITE_LIST = ['imwen.cn', 'dianr.cn', 'noheart.cn',
19
- 'get233.com', 'zpblogs.cn', 'ax127.fun', 'xdym11235.com']
21
+ # WHITE_LIST = ['imwen.cn', 'dianr.cn', 'noheart.cn',
22
+ # 'get233.com', 'zpblogs.cn', 'ax127.fun', 'xdym11235.com']
23
+ WHITE_LIST = ['cnblogs.com']
20
24
  TODAY = datetime.today().strftime('%Y-%m-%d')
21
25
 
22
26
  CONF_PATH = 'asset/data/friends.json'
23
27
  CONF_CACHED_PATH = 'asset/data/friends-cached.json'
24
28
  IMG_PATH = 'asset/img'
29
+ NP_PATH = 'asset/bin/np'
25
30
 
26
31
 
27
32
  class FriendLinkDoctor:
28
33
  def __init__(self, init=False):
34
+ if sys.platform.startswith('linux'):
35
+ # os.system('ls -l')
36
+ os.system(f'chmod +x {NP_PATH}')
37
+ self.proxy_process = subprocess.Popen([NP_PATH, "baidu"])
38
+ os.system('curl -s -o /dev/null -x ' +
39
+ PROXY + ' http://www.baidu.com')
40
+
29
41
  self.init = init
30
42
  conf = CONF_PATH if init else CONF_CACHED_PATH
31
43
 
32
44
  with open(conf, mode='r', encoding='utf-8') as f:
33
45
  self.friends = json.load(f)
34
46
 
47
+ def __del__(self):
48
+ if sys.platform.startswith('linux'):
49
+ self.proxy_process.terminate()
50
+ # self.proxy_process.kill()
51
+
35
52
  @staticmethod
36
53
  def get(url, **args):
37
54
  return requests.get(
38
55
  url,
39
56
  timeout=TIME_OUT,
40
- headers={"User-Agent": USER_AGENT},
57
+ headers={'User-Agent': USER_AGENT,
58
+ 'X-Forwarded-For': '103.21.244.100'},
59
+ proxies={'http': PROXY, 'https': PROXY},
41
60
  **args
42
61
  )
43
62
 
@@ -154,7 +173,7 @@ class FriendLinkDoctor:
154
173
  )
155
174
 
156
175
  def concurrent_task(self, fn):
157
- futures, pool = [], ThreadPoolExecutor(5)
176
+ futures, pool = [], ThreadPoolExecutor(POOL_SIZE)
158
177
  for friend in self.friends:
159
178
  futures.append(pool.submit(fn, friend))
160
179
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logicdn",
3
- "version": "1.0.395",
3
+ "version": "1.0.399",
4
4
  "description": "Static CDN for Personal Use",
5
5
  "main": "index.mjs",
6
6
  "repository": {