Guest User

Untitled

a guest
Jun 1st, 2025
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.63 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import json
  3. import urllib.parse
  4.  
  5. import bs4
  6. import requests
  7. from x_client_transaction import ClientTransaction
  8. from dotenv import dotenv_values
  9. from x_client_transaction.utils import (
  10.     generate_headers,
  11.     get_ondemand_file_url,
  12.     handle_x_migration,
  13. )
  14.  
  15.  
  16. def shitters_by_shitter(cookies, community_id='1818313839319929273', cursor=None):
  17.     session = requests.Session() # Generates Transaction ID
  18.     session.headers = generate_headers()
  19.     home_page_response = handle_x_migration(session)
  20.     ondemand_file_url = get_ondemand_file_url(response=home_page_response)
  21.     ondemand_file_response = bs4.BeautifulSoup(session.get(url=ondemand_file_url).content, 'html.parser')
  22.     ct = ClientTransaction(home_page_response, ondemand_file_response)
  23.  
  24.     endpoint_url = "https://x.com/i/api/graphql/gwNDrhzDr9kuoulEqgSQcQ/membersSliceTimeline_Query"
  25.     http_method = "GET"
  26.     endpoint_url_path = urllib.parse.urlparse(url=endpoint_url).path
  27.     transaction_id = ct.generate_transaction_id(method=http_method, path=endpoint_url_path)
  28.  
  29.     headers = { # Sets Transaction ID
  30.         'accept': '*/*',
  31.         'accept-language': 'en-US,en;q=0.9',
  32.         'authorization': cookies['bearer_token'],
  33.         'cache-control': 'no-cache',
  34.         'content-type': 'application/json',
  35.         'pragma': 'no-cache',
  36.         'priority': 'u=1, i',
  37.         'referer': 'https://x.com/',
  38.         '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',
  39.         'x-csrf-token': cookies['ct0'],
  40.         'x-twitter-active-user': 'yes',
  41.         'x-twitter-auth-type': 'OAuth2Session',
  42.         'x-twitter-client-language': 'en',
  43.         'x-client-transaction-id' : transaction_id
  44.     }
  45.     variables = {'communityId': community_id, 'cursor': cursor}
  46.     features = {
  47.         'responsive_web_graphql_timeline_navigation_enabled': True,
  48.     }
  49.     params = {'variables': variables, 'features': features}
  50.     params = urllib.parse.urlencode({k: json.dumps(v, separators = (',', ':')) for k, v in params.items()}, quote_via = urllib.parse.quote)
  51.     response = requests.get(endpoint_url, params=params, cookies=cookies, headers=headers).json()
  52.     return response
  53.  
  54. def mute_or_block_shitter(cookies, shitter, shit='mutes'):
  55.     session = requests.Session() # Generates Transaction ID
  56.     session.headers = generate_headers()
  57.     home_page_response = handle_x_migration(session)
  58.     ondemand_file_url = get_ondemand_file_url(response=home_page_response)
  59.     ondemand_file_response = bs4.BeautifulSoup(session.get(url=ondemand_file_url).content, 'html.parser')
  60.     ct = ClientTransaction(home_page_response, ondemand_file_response)
  61.  
  62.     endpoint_url = None
  63.     if shit == 'blocks':
  64.         endpoint_url = 'https://x.com/i/api/1.1/blocks/create.json'
  65.     else:
  66.         endpoint_url = 'https://x.com/i/api/1.1/mutes/users/create.json'
  67.     http_method = "POST"
  68.     endpoint_url_path = urllib.parse.urlparse(url=endpoint_url).path
  69.     transaction_id = ct.generate_transaction_id(method=http_method, path=endpoint_url_path)
  70.  
  71.     headers = { # Sets Transaction ID
  72.         'accept': '*/*',
  73.         'accept-language': 'en-US,en;q=0.9',
  74.         'authorization': cookies['bearer_token'],
  75.         'cache-control': 'no-cache',
  76.         'content-type': 'application/x-www-form-urlencoded',
  77.         'pragma': 'no-cache',
  78.         'priority': 'u=1, i',
  79.         'referer': 'https://x.com/',
  80.         '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',
  81.         'x-csrf-token': cookies['ct0'],
  82.         'x-twitter-active-user': 'yes',
  83.         'x-twitter-auth-type': 'OAuth2Session',
  84.         'x-twitter-client-language': 'en',
  85.         'x-client-transaction-id' : transaction_id
  86.     }
  87.     response = requests.post(endpoint_url, cookies=cookies, headers=headers, data=f"user_id={shitter}")
  88.     return response
  89.  
  90.  
  91. bearer_token = "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
  92.  
  93.  
  94. next_cursor = None
  95.  
  96. ct0 = dotenv_values()['TWITTER_CSRF_TOKEN']
  97. auth_token = dotenv_values()['TWITTER_AUTH_TOKEN']
  98.  
  99. while True:
  100.  
  101.     response = shitters_by_shitter(cursor=next_cursor, cookies={"ct0": ct0, "auth_token": auth_token, "bearer_token": bearer_token})
  102.     with open(f"users_by_ids.json", "w", encoding="utf-8") as f:
  103.         json.dump(response, f, ensure_ascii=False, indent=4)
  104.    
  105.     members_slice = response['data']['communityResults']['result']['members_slice']
  106.  
  107.     prev_cursor = next_cursor
  108.    
  109.     try:
  110.         next_cursor = members_slice['slice_info']['next_cursor']
  111.     except:
  112.         pass
  113.    
  114.     print(next_cursor)
  115.    
  116.     for result in members_slice['items_results']:
  117.         result = result['result']
  118.         is_blocked = result['relationship_perspectives']['blocking']
  119.         if is_blocked:
  120.             print(f"Already Blocked Shitter: {result['core']['screen_name']} ({result['legacy']['id_str']})")
  121.             continue
  122.         print(f"Shitter: {result['core']['screen_name']} ({result['legacy']['id_str']})")
  123.  
  124.         _response = mute_or_block_shitter(shitter=result['legacy']['id_str'], cookies={"ct0": ct0, "auth_token": auth_token, "bearer_token": bearer_token})
  125.         _response = mute_or_block_shitter(shit='blocks', shitter=result['legacy']['id_str'], cookies={"ct0": ct0, "auth_token": auth_token, "bearer_token": bearer_token})
  126.         #import pprint
  127.         #pprint.pprint(_response)
  128.         #break
  129.  
  130.     if next_cursor == None:
  131.         break
  132.     if next_cursor != None and prev_cursor == next_cursor:
  133.         break
  134.     #break
  135.  
Advertisement
Add Comment
Please, Sign In to add comment