<commit_before>

import facepy
import auth
import requests
from datetime import datetime, timedelta


class MyFB:

    def __init__(self, extended_token, extended_token_time, extended_token_flag):
        self.unix_time = datetime(1970, 1, 1)
        self.myAuth = auth.MyAuth()
        self.extended_token_flag = extended_token_flag
        self.extended_token = extended_token
        self.extended_token_time = self.unix_time + timedelta(seconds=extended_token_time)
        self.machine_id = self.myAuth.get_facebook_machine_id()

    def get_extended_token(self):
        expiry_time = int((self.extended_token_time - self.unix_time).total_seconds())
        return [self.extended_token, expiry_time, self.extended_token_flag]

    def generate_extended_token(self):
        link1 = "https://graph.facebook.com/oauth/client_code?" +\
            "access_token=" + self.extended_token +\
            "&client_secret=" + self.myAuth.get_facebook_app_secret() +\
            "&redirect_uri=" + self.myAuth.get_facebook_redirect_uri() +\
            "&client_id=" + self.myAuth.get_facebook_app_id()
        my_session = requests.Session()
        requested_data = my_session.get(link1).content
        print("Requested data is --- {}".format(requested_data))
        my_code = requested_data['code']

        link2 ="https://graph.facebook.com/oauth/access_token?" +\
            "code=" + my_code +\
            "&client_id=" + self.myAuth.get_facebook_app_id() +\
            "&redirect_uri=" + self.myAuth.get_facebook_redirect_uri() +\
            "&machine_id=" + self.machine_id
        my_session = requests.Session()
        requested_data = my_session.get(link2).content

        self.machine_id = requested_data['machine_id']
        self.extended_token = requested_data['access_token']<commit_msg>finally working auto renew FB extended token !?!?<commit_after>
import json
import requests
import facepy
import auth
from datetime import datetime, timedelta


class MyFB:

    def __init__(self, extended_token, extended_token_time, extended_token_flag):
        self.unix_time = datetime(1970, 1, 1)
        self.myAuth = auth.MyAuth()
        self.extended_token_flag = extended_token_flag
        self.extended_token = extended_token
        self.extended_token_time = self.unix_time + timedelta(seconds=extended_token_time)
        self.machine_id = self.myAuth.get_facebook_machine_id()

    def get_extended_token(self):
        expiry_time = int((self.extended_token_time - self.unix_time).total_seconds())
        return [self.extended_token, expiry_time, self.extended_token_flag]

    def generate_extended_token(self):
        link1 = "https://graph.facebook.com/oauth/client_code?" +\
            "access_token=" + self.extended_token +\
            "&client_secret=" + self.myAuth.get_facebook_app_secret() +\
            "&redirect_uri=" + self.myAuth.get_facebook_redirect_uri() +\
            "&client_id=" + self.myAuth.get_facebook_app_id()
        my_session = requests.Session()
        requested_data = json.loads(my_session.get(link1).content)
        print("Requested data is --- {}".format(requested_data))
        my_code = str(requested_data['code'])

        link2 ="https://graph.facebook.com/oauth/access_token?" +\
            "code=" + my_code +\
            "&client_id=" + self.myAuth.get_facebook_app_id() +\
            "&redirect_uri=" + self.myAuth.get_facebook_redirect_uri() +\
            "&machine_id=" + self.machine_id
        my_session = requests.Session()
        requested_data = json.loads(my_session.get(link2).content)
        print("Requested data is --- {}".format(requested_data))
        self.machine_id = str(requested_data['machine_id'])
        self.extended_token = str(requested_data['access_token'])
{'fraction_non_alphanumeric': 0.11724137931034483, 'fraction_numerical': 0.005305039787798408, 'mean_word_length': 3.1946607341490547, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6548117', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1145, 'n_words': 178}