"""upload_token.py"""
import json,requests
import google_auth_oauthlib.flow
CF_API="https://ytnews-api.maclub7.workers.dev"
CLIENT_SECRETS=r"C:\youtube-news\oauth-client.json"
SCOPES=["https://www.googleapis.com/auth/youtube.upload"]
def main():
    flow=google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS,SCOPES)
    credentials=flow.run_local_server(port=0)
    token_data={"token":credentials.token,"refresh_token":credentials.refresh_token,"token_uri":credentials.token_uri,"client_id":credentials.client_id,"client_secret":credentials.client_secret,"scopes":list(credentials.scopes)}
    with open(r"C:\youtube-news\token.json","w") as f: json.dump(token_data,f)
    res=requests.post(CF_API+"/save-token",json=token_data,timeout=10)
    print("완료" if res.status_code==200 else "실패")
    input("엔터...")
if __name__=="__main__": main()
