mirror of
https://github.com/zedeus/nitter.git
synced 2025-12-06 03:55:36 -05:00
fix: correct argument parsing for --append flag in get_web_session.py (#1305)
* fix: correct argument parsing for --append flag * fix: strip quotes from extracted user_id in twid cookie
This commit is contained in:
@@ -28,6 +28,7 @@ import json
|
|||||||
import asyncio
|
import asyncio
|
||||||
import pyotp
|
import pyotp
|
||||||
import nodriver as uc
|
import nodriver as uc
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
async def login_and_get_cookies(username, password, totp_seed=None, headless=False):
|
async def login_and_get_cookies(username, password, totp_seed=None, headless=False):
|
||||||
@@ -76,9 +77,9 @@ async def login_and_get_cookies(username, password, totp_seed=None, headless=Fal
|
|||||||
twid = cookies_dict['twid']
|
twid = cookies_dict['twid']
|
||||||
# Try to extract the ID from twid (format: u%3D<id> or u=<id>)
|
# Try to extract the ID from twid (format: u%3D<id> or u=<id>)
|
||||||
if 'u%3D' in twid:
|
if 'u%3D' in twid:
|
||||||
user_id = twid.split('u%3D')[1].split('&')[0]
|
user_id = twid.split('u%3D')[1].split('&')[0].strip('"')
|
||||||
elif 'u=' in twid:
|
elif 'u=' in twid:
|
||||||
user_id = twid.split('u=')[1].split('&')[0]
|
user_id = twid.split('u=')[1].split('&')[0].strip('"')
|
||||||
|
|
||||||
cookies_dict['username'] = username
|
cookies_dict['username'] = username
|
||||||
if user_id:
|
if user_id:
|
||||||
@@ -106,13 +107,27 @@ async def main():
|
|||||||
headless = False
|
headless = False
|
||||||
|
|
||||||
# Parse optional arguments
|
# Parse optional arguments
|
||||||
for i, arg in enumerate(sys.argv[3:], 3):
|
i = 3
|
||||||
if arg == '--append' and i + 1 < len(sys.argv):
|
while i < len(sys.argv):
|
||||||
append_file = sys.argv[i + 1]
|
arg = sys.argv[i]
|
||||||
|
if arg == '--append':
|
||||||
|
if i + 1 < len(sys.argv):
|
||||||
|
append_file = sys.argv[i + 1]
|
||||||
|
i += 2 # Skip '--append' and filename
|
||||||
|
else:
|
||||||
|
print('[!] Error: --append requires a filename', file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
elif arg == '--headless':
|
elif arg == '--headless':
|
||||||
headless = True
|
headless = True
|
||||||
|
i += 1
|
||||||
elif not arg.startswith('--'):
|
elif not arg.startswith('--'):
|
||||||
totp_seed = arg
|
if totp_seed is None:
|
||||||
|
totp_seed = arg
|
||||||
|
i += 1
|
||||||
|
else:
|
||||||
|
# Unkown args
|
||||||
|
print(f'[!] Warning: Unknown argument: {arg}', file=sys.stderr)
|
||||||
|
i += 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cookies = await login_and_get_cookies(username, password, totp_seed, headless)
|
cookies = await login_and_get_cookies(username, password, totp_seed, headless)
|
||||||
|
|||||||
Reference in New Issue
Block a user