xjf6b commited on
Commit
ea9a0dd
·
verified ·
1 Parent(s): 94be149

Update merged2upload.py

Browse files
Files changed (1) hide show
  1. merged2upload.py +20 -21
merged2upload.py CHANGED
@@ -1,14 +1,18 @@
1
  import requests
2
  import os
 
 
 
3
 
4
  def fetch_content(url):
5
- print(f"Fetching content from: {url}")
 
6
  try:
7
- response = requests.get(url, verify=False)
8
  response.raise_for_status()
9
  return response.text
10
  except requests.RequestException as e:
11
- print(f"Error fetching {url}: {e}")
12
  return None
13
 
14
  def upload_to_gist(content, gist_id, github_token):
@@ -24,27 +28,24 @@ def upload_to_gist(content, gist_id, github_token):
24
  }
25
  }
26
  }
 
 
27
  try:
28
- response = requests.patch(url, headers=headers, json=data)
29
  response.raise_for_status()
30
- print(f"Successfully updated Gist: {gist_id}")
31
  except requests.RequestException as e:
32
- print(f"Error updating Gist: {e}")
33
 
34
  def main():
35
- file_path = '/app/aggregator/data/subscribes.txt'
36
 
37
- if not os.path.exists(file_path):
38
- print(f"Warning: {file_path} does not exist. Creating an empty file.")
39
- os.makedirs(os.path.dirname(file_path), exist_ok=True)
40
- open(file_path, 'w').close()
41
-
42
  try:
43
  with open(file_path, 'r') as file:
44
  urls = file.read().strip().split('\n')
45
  except FileNotFoundError:
46
- print(f"Error: {file_path} not found. Proceeding with an empty list of URLs.")
47
- urls = []
48
 
49
  all_contents = []
50
 
@@ -55,15 +56,13 @@ def main():
55
 
56
  merged_content = "\n".join(all_contents)
57
 
58
- merged_file_path = '/app/aggregator/data/merged.txt'
59
- os.makedirs(os.path.dirname(merged_file_path), exist_ok=True)
60
- with open(merged_file_path, 'w') as file:
61
- file.write(merged_content)
62
- print(f"Merged content written to {merged_file_path}")
63
-
64
- # Upload the merged content to the Gist
65
  github_token = os.getenv('GITHUB_TOKEN')
66
  gist_id = os.getenv('GITHUB_GIST_ID')
 
 
 
 
 
67
  upload_to_gist(merged_content, gist_id, github_token)
68
 
69
  if __name__ == "__main__":
 
1
  import requests
2
  import os
3
+ import logging
4
+
5
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
6
 
7
  def fetch_content(url):
8
+ proxy = os.getenv('PROXY')
9
+ proxies = {'http': proxy, 'https': proxy} if proxy else None
10
  try:
11
+ response = requests.get(url, verify=False, proxies=proxies)
12
  response.raise_for_status()
13
  return response.text
14
  except requests.RequestException as e:
15
+ logging.error(f"Error fetching {url}: {e}")
16
  return None
17
 
18
  def upload_to_gist(content, gist_id, github_token):
 
28
  }
29
  }
30
  }
31
+ proxy = os.getenv('PROXY')
32
+ proxies = {'http': proxy, 'https': proxy} if proxy else None
33
  try:
34
+ response = requests.patch(url, headers=headers, json=data, proxies=proxies)
35
  response.raise_for_status()
36
+ logging.info(f"Successfully updated Gist: {gist_id}")
37
  except requests.RequestException as e:
38
+ logging.error(f"Error updating Gist: {e}")
39
 
40
  def main():
41
+ file_path = '/app/subscribes.txt'
42
 
 
 
 
 
 
43
  try:
44
  with open(file_path, 'r') as file:
45
  urls = file.read().strip().split('\n')
46
  except FileNotFoundError:
47
+ logging.error(f"Error: {file_path} not found. Exiting.")
48
+ return
49
 
50
  all_contents = []
51
 
 
56
 
57
  merged_content = "\n".join(all_contents)
58
 
 
 
 
 
 
 
 
59
  github_token = os.getenv('GITHUB_TOKEN')
60
  gist_id = os.getenv('GITHUB_GIST_ID')
61
+
62
+ if not github_token or not gist_id:
63
+ logging.error("GITHUB_TOKEN or GITHUB_GIST_ID not set. Exiting.")
64
+ return
65
+
66
  upload_to_gist(merged_content, gist_id, github_token)
67
 
68
  if __name__ == "__main__":