|
18 | 18 | import argparse |
19 | 19 | import requests |
20 | 20 | import json |
| 21 | +import re |
| 22 | +from urllib.parse import urljoin |
21 | 23 | from colorama import init, Fore, Style |
22 | 24 |
|
23 | 25 | __author__ = "Alexandre Borges" |
24 | 26 | __copyright__ = "Copyright 2025, Alexandre Borges" |
25 | 27 | __license__ = "GNU General Public License v3.0" |
26 | | -__version__ = "1.4" |
| 28 | +__version__ = "1.5" |
27 | 29 | __email__ = "reverseexploit@proton.me" |
28 | 30 |
|
29 | 31 | # Constants |
30 | | -CFP_URL = 'https://api.cfptime.org/api/cfps/' |
31 | | -UPCOMING_URL = 'https://api.cfptime.org/api/upcoming/' |
| 32 | + |
| 33 | +ORIG_URL = 'https://api.cfptime.org' |
| 34 | +CFP_URL = 'https://api.cfptime.org/api/cfps' |
| 35 | +UPCOMING_URL = 'https://api.cfptime.org/api/upcoming' |
32 | 36 |
|
33 | 37 | # Colors |
34 | 38 | COLORS = { |
|
44 | 48 | "reset": Style.RESET_ALL |
45 | 49 | } |
46 | 50 |
|
| 51 | + |
47 | 52 | def fetch_data(url): |
48 | | - """Fetch data from the given URL.""" |
| 53 | + session = requests.Session() |
| 54 | + |
| 55 | + try: |
| 56 | + init_response = session.get(ORIG_URL) |
| 57 | + init_response.raise_for_status() |
| 58 | + except requests.RequestException as e: |
| 59 | + print(f"Error during initial request: {e}") |
| 60 | + sys.exit(1) |
| 61 | + |
| 62 | + match = re.search(r'request\.headers\["X-CSRFToken"\]\s*=\s*"([^"]+)"', init_response.text) |
| 63 | + if not match: |
| 64 | + print("CSRF token not found in Swagger UI.") |
| 65 | + sys.exit(1) |
| 66 | + |
| 67 | + csrf_token = match.group(1) |
| 68 | + |
| 69 | + headers = { |
| 70 | + 'Accept': 'application/json', |
| 71 | + 'X-CSRFToken': csrf_token, |
| 72 | + 'Referer': 'https://api.cfptime.org' |
| 73 | + } |
| 74 | + |
49 | 75 | try: |
50 | | - response = requests.get(url) |
| 76 | + |
| 77 | + full_url = urljoin(url + '/', '?format=json') |
| 78 | + response = session.get(full_url, headers=headers) |
51 | 79 | response.raise_for_status() |
52 | 80 | return response.json() |
53 | 81 | except requests.RequestException as e: |
54 | | - print(COLORS["lightred"] + f"Error fetching data: {e}" + COLORS["reset"]) |
| 82 | + print(f"Error fetching data: {e}") |
55 | 83 | sys.exit(1) |
56 | 84 |
|
| 85 | + |
57 | 86 | def display_data(data, fields, headers): |
58 | 87 | """Display data in a formatted table with tabs between columns.""" |
59 | 88 | print(COLORS["reset"] + "\n" + headers) |
@@ -82,7 +111,7 @@ def cfplist(): |
82 | 111 | ] |
83 | 112 | headers = ( |
84 | 113 | "Conference Name".ljust(35) + "\t" + |
85 | | - "CFP End".ljust(12) + "\t" + |
| 114 | + "CFP End".ljust(15) + "\t" + |
86 | 115 | "Conf Start".ljust(10) + "\t" + |
87 | 116 | "City".ljust(16) + "\t" + |
88 | 117 | "Twitter".ljust(18) + "\t" + |
|
0 commit comments