Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pip install openpyxl
- #pip install xlrd
- #pip install pandas
- from plemmy import LemmyHttp
- from plemmy.responses import PostResponse
- import pandas as pd
- import xlrd
- import datetime
- import requests,json
- # Get the current date as string
- current_date = str(datetime.date.today())
- #Import file and find today's stage information
- tdf2024 = pd.read_excel('tdf2024.xlsx', engine='openpyxl') #Import xlsx file
- tdf2024['date']=pd.to_datetime(tdf2024['date'],dayfirst=False) #Convert date column to ISO8601
- tdf2024.set_index('date', inplace=True)
- #Don't make a post if it is a rest day
- if tdf2024.at[current_date,'stage'] == False:
- exit()
- #Create title and body
- stage = str(int(tdf2024.at[current_date,'etape']))
- route = tdf2024.at[current_date,'route']
- stage_type = tdf2024.at[current_date,'type']
- stage_lenght = str(int(tdf2024.at[current_date,'length']))
- stage_start = tdf2024.at[current_date,'starttime']
- stage_profile = ""
- stage_map = ""
- title = "[" + current_date + "] Tour de France: " + stage + ". etape " + route
- url_post = tdf2024.at[current_date,'route map']
- body = """Så er det tid til endnu etape af Tour de France.
- Dagens etape er en """ + stage_type + """ på ruten """ + route + """ og er """ + stage_lenght + """ km lang.
- Den reelle start forventes at være kl """ + stage_start + """.
- Mere information om etapen kan ses på [TV2's hjemmeside](https://sport.tv2.dk/cykling/2023-10-26-tour-de-france-2024-""" + stage + """-etape), samt på [Tour'ens hjemmeside](https://www.letour.fr/en/stage-""" + stage + """)
- """ + stage_profile + """
- Denne tråd oprettes automatisk af [botten](https://github.com/Fedihosting-Foundation/plemmy) på dagen for hver etape kl 6.
- """
- #Find community id
- params = {
- 'name': 'sport',
- }
- response = requests.get('https://feddit.dk/api/v3/community', params=params).json()
- community = response['community_view']['community']
- community_id = community['id']
- # create object for feddit.dk, log in
- srv = LemmyHttp("https://feddit.dk")
- #srv = LemmyHttp("https://voyager.lemmy.ml")
- srv.login("President_Pyrus", "hunter2")
- # create post, parse JSON
- #api_response = srv.create_post(67912, title, body)
- api_response = srv.create_post(community_id, title, body, url = url_post)
- #11: To get a community ID, simply curl
- #https://instance.tld/api/v3/community?name=community_name
- #and the value will be in "community_view">"community">"id"
- #v3: API version: https://join-lemmy.org/docs/contributors/04-api.html
- response = PostResponse(api_response)
- post = response.post_view.post
- print(post.creator_id)
- print(post.community_id)
- print(post.name)
- print(post.body)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement