Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import json
- import urllib.parse
- import bs4
- import requests
- from x_client_transaction import ClientTransaction
- from dotenv import dotenv_values
- from x_client_transaction.utils import (
- generate_headers,
- get_ondemand_file_url,
- handle_x_migration,
- )
- def shitters_by_shitter(cookies, community_id='1818313839319929273', cursor=None):
- session = requests.Session() # Generates Transaction ID
- session.headers = generate_headers()
- home_page_response = handle_x_migration(session)
- ondemand_file_url = get_ondemand_file_url(response=home_page_response)
- ondemand_file_response = bs4.BeautifulSoup(session.get(url=ondemand_file_url).content, 'html.parser')
- ct = ClientTransaction(home_page_response, ondemand_file_response)
- endpoint_url = "https://x.com/i/api/graphql/gwNDrhzDr9kuoulEqgSQcQ/membersSliceTimeline_Query"
- http_method = "GET"
- endpoint_url_path = urllib.parse.urlparse(url=endpoint_url).path
- transaction_id = ct.generate_transaction_id(method=http_method, path=endpoint_url_path)
- headers = { # Sets Transaction ID
- 'accept': '*/*',
- 'accept-language': 'en-US,en;q=0.9',
- 'authorization': cookies['bearer_token'],
- 'cache-control': 'no-cache',
- 'content-type': 'application/json',
- 'pragma': 'no-cache',
- 'priority': 'u=1, i',
- 'referer': 'https://x.com/',
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
- 'x-csrf-token': cookies['ct0'],
- 'x-twitter-active-user': 'yes',
- 'x-twitter-auth-type': 'OAuth2Session',
- 'x-twitter-client-language': 'en',
- 'x-client-transaction-id' : transaction_id
- }
- variables = {'communityId': community_id, 'cursor': cursor}
- features = {
- 'responsive_web_graphql_timeline_navigation_enabled': True,
- }
- params = {'variables': variables, 'features': features}
- params = urllib.parse.urlencode({k: json.dumps(v, separators = (',', ':')) for k, v in params.items()}, quote_via = urllib.parse.quote)
- response = requests.get(endpoint_url, params=params, cookies=cookies, headers=headers).json()
- return response
- def mute_or_block_shitter(cookies, shitter, shit='mutes'):
- session = requests.Session() # Generates Transaction ID
- session.headers = generate_headers()
- home_page_response = handle_x_migration(session)
- ondemand_file_url = get_ondemand_file_url(response=home_page_response)
- ondemand_file_response = bs4.BeautifulSoup(session.get(url=ondemand_file_url).content, 'html.parser')
- ct = ClientTransaction(home_page_response, ondemand_file_response)
- endpoint_url = None
- if shit == 'blocks':
- endpoint_url = 'https://x.com/i/api/1.1/blocks/create.json'
- else:
- endpoint_url = 'https://x.com/i/api/1.1/mutes/users/create.json'
- http_method = "POST"
- endpoint_url_path = urllib.parse.urlparse(url=endpoint_url).path
- transaction_id = ct.generate_transaction_id(method=http_method, path=endpoint_url_path)
- headers = { # Sets Transaction ID
- 'accept': '*/*',
- 'accept-language': 'en-US,en;q=0.9',
- 'authorization': cookies['bearer_token'],
- 'cache-control': 'no-cache',
- 'content-type': 'application/x-www-form-urlencoded',
- 'pragma': 'no-cache',
- 'priority': 'u=1, i',
- 'referer': 'https://x.com/',
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
- 'x-csrf-token': cookies['ct0'],
- 'x-twitter-active-user': 'yes',
- 'x-twitter-auth-type': 'OAuth2Session',
- 'x-twitter-client-language': 'en',
- 'x-client-transaction-id' : transaction_id
- }
- response = requests.post(endpoint_url, cookies=cookies, headers=headers, data=f"user_id={shitter}")
- return response
- bearer_token = "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
- next_cursor = None
- ct0 = dotenv_values()['TWITTER_CSRF_TOKEN']
- auth_token = dotenv_values()['TWITTER_AUTH_TOKEN']
- while True:
- response = shitters_by_shitter(cursor=next_cursor, cookies={"ct0": ct0, "auth_token": auth_token, "bearer_token": bearer_token})
- with open(f"users_by_ids.json", "w", encoding="utf-8") as f:
- json.dump(response, f, ensure_ascii=False, indent=4)
- members_slice = response['data']['communityResults']['result']['members_slice']
- prev_cursor = next_cursor
- try:
- next_cursor = members_slice['slice_info']['next_cursor']
- except:
- pass
- print(next_cursor)
- for result in members_slice['items_results']:
- result = result['result']
- is_blocked = result['relationship_perspectives']['blocking']
- if is_blocked:
- print(f"Already Blocked Shitter: {result['core']['screen_name']} ({result['legacy']['id_str']})")
- continue
- print(f"Shitter: {result['core']['screen_name']} ({result['legacy']['id_str']})")
- _response = mute_or_block_shitter(shitter=result['legacy']['id_str'], cookies={"ct0": ct0, "auth_token": auth_token, "bearer_token": bearer_token})
- _response = mute_or_block_shitter(shit='blocks', shitter=result['legacy']['id_str'], cookies={"ct0": ct0, "auth_token": auth_token, "bearer_token": bearer_token})
- #import pprint
- #pprint.pprint(_response)
- #break
- if next_cursor == None:
- break
- if next_cursor != None and prev_cursor == next_cursor:
- break
- #break
Advertisement
Add Comment
Please, Sign In to add comment