<commit_before>import base64
import datetime
import hmac
import json
import random
from hashlib import sha1
from urllib.parse import urlparse
import requests

s = requests.Session()


class JodelAccount:
    post_colors = ['9EC41C', 'FF9908', 'DD5F5F', '8ABDB0', '066A3CB', 'FFBA00']
    client_id = '"client_id":"81e8a76e-1e02-4d17-9ba0-8a7020261b26"'
    api_url = "https://api.go-tellm.com/api%s"
    access_token = None
    device_uid = None

    def __init__(self, lat, lng, city, country=None, name=None, update_location=True,
                 access_token=None, device_uid=None, refresh_token=None, distinct_id=None, expiration_date=None):
        self.lat, self.lng, self.location_str = lat, lng, self._get_location_string(lat, lng, city, country, name)

        if access_token and device_uid and refresh_token and distinct_id and expiration_date:
            self.expiration_date = expiration_date
            self.distinct_id = distinct_id
            self.refresh_token = refresh_token
            self.device_uid = device_uid
            self.access_token = access_token
            if update_location:
                r = self.set_location(lat, lng, city, country, name)
                print(r)

        else:
            print("Creating new account.")
            r = self.refresh_all_tokens()
            if r[0] != 200:
                print("Error creating new account: " + str(r))

    def _send_request(self, method, endpoint, payload=None):
        url = self.api_url % endpoint
        headers = {'User-Agent': 'Jodel/4.4.9 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )',
                   'Accept-Encoding': 'gzip',
                   'Content-Type': 'application/json; charset=UTF-8'}
        if self.access_token:
            headers['Authorization'] = "Bearer " + self.access_token

        self._sign_request(method, url, headers, payload)

        payload = payload.encode('utf-8') if payload is not None else None

        resp = s.request(method=method, url=url, data=payload, headers=headers)
        try:
            resp_text = json.loads(resp.text, encoding="utf-8")
        except:
            resp_text = resp.text

        return resp.status_code, resp_text

    def _sign_request(self, method, url, headers, payload=None):
        timestamp = datetime.datetime.utcnow().isoformat()[:-7] + "Z"

        req = [method,
               urlparse(url).netloc,
               "443",
               urlparse(url).path,
               self.access_token if self.access_token else "",
               timestamp]
        req.extend(sorted(urlparse(url).query.replace("=", "%").split("&")))
        req.append(payload if payload else "")

        secret = bytearray([106, 99, 85, 119, 97, 78, 78, 90, 119, 84, 83, 97, 77, 103, 98, 69, 69, 111, 104, 88, 74,
                            104, 110, 99, 118, 121, 73, 77, 100, 110, 90, 107, 70, 101, 99, 87, 102, 80, 79, 85])
        signature = hmac.new(secret, "%".join(req).encode("utf-8"), sha1).hexdigest().upper()

        headers['X-Authorization'] = 'HMAC ' + signature
        headers['X-Client-Type'] = 'android_4.14.1'
        headers['X-Timestamp'] = timestamp
        headers['X-Api-Version'] = '0.2'<commit_msg>update client secret<commit_after>import base64
import datetime
import hmac
import json
import random
from hashlib import sha1
from urllib.parse import urlparse
import requests

s = requests.Session()


class JodelAccount:
    post_colors = ['9EC41C', 'FF9908', 'DD5F5F', '8ABDB0', '066A3CB', 'FFBA00']
    client_id = '"client_id":"81e8a76e-1e02-4d17-9ba0-8a7020261b26"'
    api_url = "https://api.go-tellm.com/api%s"
    access_token = None
    device_uid = None

    def __init__(self, lat, lng, city, country=None, name=None, update_location=True,
                 access_token=None, device_uid=None, refresh_token=None, distinct_id=None, expiration_date=None):
        self.lat, self.lng, self.location_str = lat, lng, self._get_location_string(lat, lng, city, country, name)

        if access_token and device_uid and refresh_token and distinct_id and expiration_date:
            self.expiration_date = expiration_date
            self.distinct_id = distinct_id
            self.refresh_token = refresh_token
            self.device_uid = device_uid
            self.access_token = access_token
            if update_location:
                r = self.set_location(lat, lng, city, country, name)
                print(r)

        else:
            print("Creating new account.")
            r = self.refresh_all_tokens()
            if r[0] != 200:
                raise Exception("Error creating new account: "+str(r))
                #print("Error creating new account: " + str(r))

    def _send_request(self, method, endpoint, payload=None):
        url = self.api_url % endpoint
        headers = {'User-Agent': 'Jodel/4.4.9 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )',
                   'Accept-Encoding': 'gzip',
                   'Content-Type': 'application/json; charset=UTF-8'}
        if self.access_token:
            headers['Authorization'] = "Bearer " + self.access_token

        self._sign_request(method, url, headers, payload)

        payload = payload.encode('utf-8') if payload is not None else None

        resp = s.request(method=method, url=url, data=payload, headers=headers)
        try:
            resp_text = json.loads(resp.text, encoding="utf-8")
        except:
            resp_text = resp.text

        return resp.status_code, resp_text

    def _sign_request(self, method, url, headers, payload=None):
        timestamp = datetime.datetime.utcnow().isoformat()[:-7] + "Z"

        req = [method,
               urlparse(url).netloc,
               "443",
               urlparse(url).path,
               self.access_token if self.access_token else "",
               timestamp]
        req.extend(sorted(urlparse(url).query.replace("=", "%").split("&")))
        req.append(payload if payload else "")

        secret = bytearray([74, 121, 109, 82, 78, 107, 79, 71, 68, 85, 72, 81, 77, 86, 101, 86, 118, 100, 122, 118, 
                            97, 120, 99, 75, 97, 101, 117, 74, 75, 87, 87, 70, 101, 105, 104, 110, 89, 110, 115, 89])
        signature = hmac.new(secret, "%".join(req).encode("utf-8"), sha1).hexdigest().upper()

        headers['X-Authorization'] = 'HMAC ' + signature
        headers['X-Client-Type'] = 'android_4.17.1'
        headers['X-Timestamp'] = timestamp
        headers['X-Api-Version'] = '0.2'
{'fraction_non_alphanumeric': 0.1291769801980198, 'fraction_numerical': 0.05167079207920792, 'mean_word_length': 2.4351753453772584, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1008641', 'n_tokens_mistral': 2283, 'n_tokens_neox': 1992, 'n_words': 483}