|
|
from taipy import Gui |
|
|
from taipy.gui import navigate |
|
|
import taipy.gui.builder as tgb |
|
|
from functi import * |
|
|
from Source_manage import source_page, menu_page |
|
|
from Post_management import Post_manag |
|
|
from flask import Flask, request |
|
|
from urllib.parse import urlparse, parse_qs |
|
|
import time |
|
|
import logging |
|
|
logging.getLogger('requests_oauthlib').setLevel(logging.DEBUG) |
|
|
|
|
|
|
|
|
import requests |
|
|
|
|
|
def obtenir_access_token(code, client_id, client_secret, redirect_uri): |
|
|
url = "https://www.linkedin.com/oauth/v2/accessToken" |
|
|
headers = { |
|
|
"Content-Type": "application/x-www-form-urlencoded" |
|
|
} |
|
|
data = { |
|
|
"grant_type": "authorization_code", |
|
|
"code": code, |
|
|
"redirect_uri": redirect_uri, |
|
|
"client_id": client_id, |
|
|
"client_secret": client_secret |
|
|
} |
|
|
|
|
|
response = requests.post(url, headers=headers, data=data) |
|
|
response.raise_for_status() |
|
|
return response.json() |
|
|
|
|
|
|
|
|
|
|
|
presentation_text = """ |
|
|
Découvrez Lin votre assistant community manager sur Linkedin |
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_navigate(state, page_name: str): |
|
|
if page_name == "callback": |
|
|
raw = request.environ.get("REQUEST_URI", "") |
|
|
|
|
|
|
|
|
full = request.scheme + "://" + request.host + raw |
|
|
state.authorization_url = full |
|
|
state.authorization_url = state.authorization_url.replace("/taipy-jsx", "") |
|
|
state.authorization_url = state.authorization_url.rsplit("&v", 1)[0] |
|
|
state.authorization_url = state.authorization_url.replace("http://", "https://") |
|
|
print(state.authorization_url,flush = True) |
|
|
parsed = urlparse(state.authorization_url) |
|
|
|
|
|
|
|
|
params = parse_qs(parsed.query) |
|
|
|
|
|
|
|
|
state_value = params.get("state", [""])[0] |
|
|
code = params.get("code", [""])[0] |
|
|
print(state_value,flush = True) |
|
|
print(state.states,flush = True) |
|
|
print(code,flush = True) |
|
|
if state_value.endswith('?'): |
|
|
state_value = state_value[:-1] |
|
|
else: |
|
|
state_value = state_value |
|
|
|
|
|
if state_value == state.states : |
|
|
if state.Linked_social_network == "Linkedin" : |
|
|
response = obtenir_access_token(code, state.client_id, state.client_secret, state.redirect_url) |
|
|
|
|
|
state.token = response["access_token"] |
|
|
|
|
|
|
|
|
url = "https://api.linkedin.com/v2/userinfo" |
|
|
headers = { |
|
|
"Authorization": f"Bearer {state.token}" |
|
|
} |
|
|
|
|
|
response_open = requests.get(url, headers=headers) |
|
|
response_open =response_open.json() |
|
|
db_manager.add_token_network(state.token,state.Linked_social_network,state.Linked_account_name,state.user_inf.user.id,response_open) |
|
|
navigate(state,"Source_Management" ) |
|
|
|
|
|
|
|
|
print(state.token,flush = True) |
|
|
else : |
|
|
print("mkjgfzmfvhsmehk") |
|
|
|
|
|
|
|
|
|
|
|
return page_name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with tgb.Page(class_name="bodyp") as callb: |
|
|
tgb.text("attendez un moment") |
|
|
|
|
|
|
|
|
with tgb.Page(class_name="bodyp") as page_appart: |
|
|
|
|
|
|
|
|
with tgb.part(render="{not is_logged_in}"): |
|
|
with tgb.part(class_name="presentation", height="100vh"): |
|
|
tgb.text("Lin", class_name="App_name") |
|
|
|
|
|
|
|
|
with tgb.part(class_name="presentation_text"): |
|
|
tgb.text(presentation_text, id="presentation_text_t") |
|
|
with tgb.part(class_name="auth-container"): |
|
|
|
|
|
|
|
|
|
|
|
with tgb.part(render="{not show_register}"): |
|
|
tgb.text("Login to Lin") |
|
|
tgb.input("{login_email}", label="Email", type="email",change_delay = -1,action_on_blur = True) |
|
|
tgb.input("{login_password}", label="Password", password=True,change_delay = -1,action_on_blur = True) |
|
|
tgb.button("Login", on_action=on_login ) |
|
|
tgb.button("Need an account? Register", on_action=toggle_register) |
|
|
|
|
|
|
|
|
with tgb.part(render="{show_register}"): |
|
|
tgb.text("Register for Lin", ) |
|
|
tgb.input("{register_email}", label="Email", type="email",change_delay = -1,action_on_blur = True) |
|
|
tgb.input("{register_password}", label="Password", password=True,change_delay = -1,action_on_blur = True) |
|
|
tgb.input("{confirm_password}", label="Confirm Password", password=True,change_delay = -1,action_on_blur = True) |
|
|
tgb.button("Register", on_action=on_register, class_name="auth-button") |
|
|
tgb.button("Already have an account? Login", on_action=toggle_register, ) |
|
|
|
|
|
|
|
|
with tgb.part(render="{message}"): |
|
|
tgb.text("{message}", class_name="message") |
|
|
|
|
|
|
|
|
with tgb.part(render="{is_logged_in}"): |
|
|
with tgb.part(class_name="presentation", height="100vh"): |
|
|
tgb.text("Lin", class_name="App_name") |
|
|
tgb.text(f"Welcome, {'{current_user}'}!", class_name="welcome-message") |
|
|
tgb.button("Logout", on_action=on_logout, class_name="logout-button") |
|
|
|
|
|
with tgb.part(class_name="presentation_text"): |
|
|
tgb.text(presentation_text, id="presentation_text_t") |
|
|
|
|
|
|
|
|
pages = { |
|
|
"Accueil": page_appart, |
|
|
"/": menu_page, |
|
|
"Source_Management" : source_page, |
|
|
"callback" : callb, |
|
|
"Post" : Post_manag |
|
|
} |
|
|
|
|
|
stylekit = { |
|
|
"color_primary" : "#910029", |
|
|
|
|
|
} |
|
|
|
|
|
if __name__ == "__main__": |
|
|
planning() |
|
|
|
|
|
gui = Gui(pages=pages) |
|
|
gui.run( |
|
|
debug=True, |
|
|
port=7860,host = "0.0.0.0", |
|
|
stylekit=stylekit, |
|
|
title="Lin", |
|
|
dark_mode=False, |
|
|
use_reloader=True |
|
|
) |