Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
*.json
/*.py
/node_modules
/node_modules
__pycache__/
*.pyc
*.pyo
*.pyd
.env
venv/
env/
2 changes: 1 addition & 1 deletion twikit/client/gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async def search_timeline(
}
if cursor is not None:
variables['cursor'] = cursor
return await self.gql_get(Endpoint.SEARCH_TIMELINE, variables, FEATURES)
return await self.gql_post(Endpoint.SEARCH_TIMELINE, variables, FEATURES)

async def similar_posts(self, tweet_id: str):
variables = {'tweet_id': tweet_id}
Expand Down
27 changes: 17 additions & 10 deletions twikit/x_client_transaction/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from .rotation import convert_rotation_to_matrix
from .utils import float_to_hex, is_odd, base64_encode, handle_x_migration

ON_DEMAND_FILE_REGEX = re.compile(
r"""['|\"]{1}ondemand\.s['|\"]{1}:\s*['|\"]{1}([\w]*)['|\"]{1}""", flags=(re.VERBOSE | re.MULTILINE))
ON_DEMAND_FILE_REGEX: re.Pattern = re.compile(r""",(\d+):["']ondemand\.s["']""", flags=(re.VERBOSE | re.MULTILINE))
ON_DEMAND_HASH_PATTERN: str = r',{}:\"([0-9a-f]+)\"'
INDICES_REGEX = re.compile(
r"""(\(\w{1}\[(\d{1,2})\],\s*16\))+""", flags=(re.VERBOSE | re.MULTILINE))

Expand Down Expand Up @@ -42,14 +42,21 @@ async def get_indices(self, home_page_response, session, headers):
key_byte_indices = []
response = self.validate_response(
home_page_response) or self.home_page_response
on_demand_file = ON_DEMAND_FILE_REGEX.search(str(response))
if on_demand_file:
on_demand_file_url = f"https://abs.twimg.com/responsive-web/client-web/ondemand.s.{on_demand_file.group(1)}a.js"
on_demand_file_response = await session.request(method="GET", url=on_demand_file_url, headers=headers)
key_byte_indices_match = INDICES_REGEX.finditer(
str(on_demand_file_response.text))
for item in key_byte_indices_match:
key_byte_indices.append(item.group(2))
on_demand_file_match = ON_DEMAND_FILE_REGEX.search(str(response))
if not on_demand_file_match:
raise Exception("Failed to match ON_DEMAND_FILE_REGEX in the home page response")
on_demand_file_index = on_demand_file_match.group(1)
regex = re.compile(ON_DEMAND_HASH_PATTERN.format(on_demand_file_index))
filename_match = regex.search(str(response))
if not filename_match:
raise Exception(f"Failed to match the hash pattern for on_demand_file index {on_demand_file_index}")
filename = filename_match.group(1)
on_demand_file_url = f"https://abs.twimg.com/responsive-web/client-web/ondemand.s.{filename}a.js"
on_demand_file_response = await session.request(method="GET", url=on_demand_file_url, headers=headers)
key_byte_indices_match = INDICES_REGEX.finditer(
str(on_demand_file_response.text))
for item in key_byte_indices_match:
key_byte_indices.append(item.group(2))
if not key_byte_indices:
raise Exception("Couldn't get KEY_BYTE indices")
key_byte_indices = list(map(int, key_byte_indices))
Expand Down