mirror of
https://github.com/thegeneralist01/twitter-openapi
synced 2026-01-11 07:30:37 +01:00
parent
c7d323f781
commit
99c7c0f4b9
6 changed files with 1455 additions and 110 deletions
|
|
@ -12,11 +12,16 @@ from enum import Enum
|
|||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import bs4
|
||||
import openapi_client as pt
|
||||
import requests
|
||||
import urllib3
|
||||
from x_client_transaction import ClientTransaction
|
||||
from x_client_transaction.utils import handle_x_migration
|
||||
from x_client_transaction.utils import (
|
||||
generate_headers,
|
||||
get_ondemand_file_url,
|
||||
handle_x_migration,
|
||||
)
|
||||
|
||||
warnings.filterwarnings("ignore")
|
||||
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s")
|
||||
|
|
@ -60,7 +65,20 @@ def find_name(x):
|
|||
return [x["name"]]
|
||||
|
||||
|
||||
def get_transaction_id(key):
|
||||
def get_transaction_base():
|
||||
session = requests.Session()
|
||||
session.headers = generate_headers()
|
||||
home_page_response = handle_x_migration(session=session)
|
||||
home_page = session.get(url="https://x.com")
|
||||
home_page_response = bs4.BeautifulSoup(home_page.content, "html.parser")
|
||||
ondemand_file_url = get_ondemand_file_url(response=home_page_response)
|
||||
ondemand_file = session.get(url=ondemand_file_url)
|
||||
ondemand_file_response = bs4.BeautifulSoup(ondemand_file.content, "html.parser")
|
||||
ct = ClientTransaction(home_page_response, ondemand_file_response)
|
||||
return ct
|
||||
|
||||
|
||||
def get_transaction_id(key, ct=get_transaction_base()):
|
||||
return ct.generate_transaction_id(
|
||||
method=placeholder[key]["@method"], path=placeholder[key]["@path"]
|
||||
)
|
||||
|
|
@ -282,8 +300,6 @@ if __name__ == "__main__":
|
|||
session = requests.Session()
|
||||
session.headers = get_header(latest_user_agent, "chrome")
|
||||
|
||||
ct = ClientTransaction(handle_x_migration(session))
|
||||
|
||||
error_count = 0
|
||||
|
||||
for x in [pt.DefaultApi, pt.TweetApi, pt.UserApi, pt.UsersApi, pt.UserListApi]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue