Advertisement
Yonka2019

glitter.py

Jun 26th, 2021
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.47 KB | None | 0 0
  1. import re
  2.  
  3. BUFFER = 1024
  4.  
  5.  
  6. def custom_glit_upload(sock, feed_owner_id, publisher_avatar, background_color, date, content, font_color):
  7.     """
  8.    Custom glit uploading with editable parameters (the application allows u to edit only the content label,
  9.    here you can edit additional parameters) @param sock: current opened socket @param publisher_avatar: set any
  10.    avatar ( im1->im8) @param background_color: set any background color @param date: set any date
  11.    YYYY-MM-DD'T'HH:MM:SS.MSMSMS'Z' @param content: the content of the uploaded glit @param font_color: the font
  12.    color of the text
  13.    """
  14.     sock.sendall(('550#{gli&&er}{"feed_owner_id":' + feed_owner_id + ',"publisher_id":' + MY_ID + ','
  15.                   '"publisher_screen_name":"Yonka", '
  16.                   '"publisher_avatar":"' + publisher_avatar + '","background_color":"' + background_color
  17.                   + '","date":"' + date + '",'  # UTC
  18.                   '"content":"' + content + '","font_color":"' + font_color + '","id":-1}##').encode())
  19.     print(sock.recv(BUFFER).decode())
  20.  
  21.  
  22. def custom_comment_upload(sock, content, date):
  23.     """
  24.    Custom comment uploading with editable parameters (the application allows u to edit only the content label,
  25.    here you can edit additional parameters)
  26.    @param sock: current opened socket
  27.    @param content: the content of the uploaded comment
  28.    @param date: set any date YYYY-MM-DD'T'HH:MM:SS.MSMSMS'Z'
  29.    """
  30.     sock.sendall(('650#{gli&&er}{"glit_id":5214,"user_id":' + MY_ID + ',"user_screen_name":"Yonka","id":-1,"content":"'
  31.                   + content
  32.                   + '","date":"' + date + '"}##').encode())
  33.     print(sock.recv(BUFFER))
  34.  
  35.  
  36. def get_description(sock, profile_id):
  37.     """
  38.    Returns the description (Life Motto) of the given profile (id)
  39.    @param sock: current opened socket
  40.    @param profile_id: id of the profile which we want to get his description
  41.    @return: (str) the description (Life Motto) of the profile (that we set in the settings)
  42.    """
  43.     description_pattern = r'description":"(.+?)"'
  44.     sock.sendall(('310#{gli&&er}' + profile_id + '##').encode())
  45.  
  46.     reply = sock.recv(BUFFER).decode()
  47.     print(reply)
  48.  
  49.     matches = re.search(description_pattern, reply)
  50.  
  51.     return matches.group(1)
  52.  
  53.  
  54. def login(sock, username, password, checksum):
  55.     """
  56.    login into the system
  57.    @param sock: current opened socket
  58.    @param username: user name to log with
  59.    @param password: password to log with
  60.    @param checksum: checksum of username+password
  61.    """
  62.     sock.sendall(('100#{gli&&er}{"user_name":"' + username + '","password":"' + password + '",'
  63.                   '"enable_push_notifications":true}##').encode())  # Login
  64.     sock.recv(BUFFER)
  65.     sock.sendall(('110#{gli&&er}' + str(checksum) + '##').encode())  # CHECKSUM send
  66.     reply = sock.recv(BUFFER).decode()
  67.     print(reply)
  68.  
  69.     user_id = get_id(reply)
  70.     password = get_password(reply)
  71.     screen_name = get_screen_name(reply)
  72.  
  73.     return user_id, password, screen_name
  74.  
  75.  
  76. def get_password(message):
  77.     password_pattern = r'"password":"(.+?)",'
  78.     matches = re.search(password_pattern, message)
  79.     if matches:
  80.         return matches.group(1)
  81.     else:
  82.         return None
  83.  
  84.  
  85. def get_id(message):
  86.     id_pattern = r'"id":(.+?),'
  87.     matches = re.search(id_pattern, message)
  88.     if matches:
  89.         return matches.group(1)
  90.     else:
  91.         return None
  92.  
  93.  
  94. def get_screen_name(message):
  95.     screen_name_pattern = r'"screen_name":"(.+?)",'
  96.     matches = re.search(screen_name_pattern, message)
  97.     if matches:
  98.         return matches.group(1)
  99.     else:
  100.         return None
  101.  
  102.  
  103. def calc_checksum(data):
  104.     """
  105.    Calcualtes the checksum of the given data
  106.    @param data: data to calculate his checksum
  107.    @return: calculated checksum
  108.    """
  109.     num = 0
  110.     for letter in data:
  111.         num += ord(letter)
  112.     return num
  113.  
  114.  
  115. def login_without_pass(sock, username, user_id):
  116.     logout(sock, user_id)
  117.     checksum_pattern = r"checksum: (\d+){"
  118.     sock.sendall(('100#{gli&&er}{"user_name":"' + username +
  119.                   '","password":"-----","enable_push_notifications":true}##').encode())
  120.     matches = re.search(checksum_pattern, sock.recv(BUFFER).decode())
  121.     if matches is None:
  122.         return None, None
  123.  
  124.     checksum = int(matches.group(1))
  125.     current_id, password, screen_name = login(sock, username, chr(checksum - calc_checksum(username)), checksum)
  126.  
  127.     return current_id, password, screen_name
  128.  
  129.  
  130. def logout(sock, user_id):
  131.     sock.sendall(('200#{gli&&er}' + user_id + '##').encode())
  132.     sock.recv(BUFFER).decode()
  133.  
  134.  
  135. def add_likes(sock, user_id, glit_id, user_screen_name, likes_number):
  136.     """
  137.    Add any number of likes to the given glit
  138.    @param sock: current opened glit
  139.    @param glit_id: id of the glit to add likes
  140.    @param likes_number: number of likes to add to the given glit
  141.    """
  142.     for i in range(likes_number):
  143.         sock.sendall(
  144.             ('710#{gli&&er}{"glit_id":' + glit_id + ',"user_id":' + user_id +
  145.              ',"user_screen_name":"' + user_screen_name + '","id":-1}##').encode())
  146.         print(sock.recv(BUFFER).decode())
  147.  
  148.  
  149. def get_email(sock, username):
  150.     """
  151.    Returns the email of the given username in the Glit system
  152.    @param sock: current opened socket
  153.    @param username: username to get his email
  154.    @return: (str) email of the given username
  155.    """
  156.     email_pattern = r'{"screen_name":"' + username + '".+?"mail":"(.+?)"'
  157.     sock.sendall(('300#{gli&&er}{"search_type":"SIMPLE","search_entry":"' + username + '"}##').encode())
  158.     reply = sock.recv(BUFFER).decode()
  159.     print(reply)
  160.  
  161.     matches = re.search(email_pattern, reply)
  162.  
  163.     return matches.group(1)
  164.  
  165.  
  166. def accept_glance_request(sock, future_friend_id):
  167.     """
  168.    Accept some glance request that we sent from another user
  169.    @param sock: current opened socket
  170.    @param future_friend_id: friend which we send and want to accept the glance
  171.    """
  172.     sock.sendall(('420#{gli&&er}[' + MY_ID + ',' + future_friend_id + ']##').encode())
  173.     print(sock.recv(BUFFER).decode())
  174.  
  175.  
  176. def glits_list(sock, user_id):
  177.     glit_count = 3
  178.     glits_pattern = r'"date":"(\d+?)-(\d+?)-(\d+?)T.+?"content":"(.+?)".+?"id":(\d+)'
  179.     sock.sendall(('500#{gli&&er}{"feed_owner_id":' + user_id + ',"end_date":"2021-06-26T11:01:35.206Z","glit_count":' + str(glit_count) + '}##').encode())
  180.     matches = re.findall(glits_pattern, sock.recv(BUFFER * glit_count).decode())
  181.     return matches
  182.  
  183.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement