https://qiita.com/PigeonsHouse/items/a6a6833e81c8dee384a4 Thanks to Bot Tsuyotsuyo Man who wrote this article, I was motivated.
Also, I wanted Princess Maho to speak
Also, since it's a Japanese fucking coarse fish, I don't know what I'm saying, so please call the code and do your best to understand it () ~~ I'm programming in an atmosphere ~~
Maho princess bot cute This time I would like to talk about the timetable function of Princess Maho's function.
Maho Hime Timetable Tells you the timetable. The general flow of this function is "Maho Hime Today's timetable is 1, subject name 2, subject name 3, subject name 4, subject 5, subject name", and the subject name is entered in the google spreadsheet and "Maho Hime" "Tell me the timetable" is the flow of extracting data from google spreadsheet and outputting it.
** About api ** I think it's about getting an access token and using the features of the software.
Please refer to the following URL for obtaining googlespreadsheetapi. https://qiita.com/164kondo/items/eec4d1d8fd7648217935 (I tried to access Google Spread Sheets using Python)
Consider a description that extracts the subject name from the toot and outputs it to google spreadsheet
if re.search(r'((today|Today)of(Timetable|School timetable)Is)', content): nagasa = len(content) firstclass = content[content.find('1,') + 2: content.find('2,')] secondclass = content[content.find('2,') + 2: content.find('3,')] thirdclass = content[content.find('3,') + 2: content.find('4,')] fourthclass = content[content.find('4,') + 2: content.find('5,')] fifthclass = content[content.find('5,') + 2: nagasa]
Use the find function of python to specify the location of the subject name, and put the data of the 1st period, 2nd period, ... 5th period in a variable to get the subject name.
Enter the subject name obtained in 1 in google spreadshhet
a = 3 while(str(sh.cell(a, 1).value) != ''): if str(sh.cell(a,1).value) == username: sh.update_cell(a,2,firstclass) time.sleep(1) sh.update_cell(a,3,secondclass) time.sleep(1) sh.update_cell(a,4,thirdclass) time.sleep(1) sh.update_cell(a,5,fourthclass) time.sleep(1) sh.update_cell(a,6,fifthclass) time.sleep(1) sh.update_cell(a,7,'ok') time.sleep(1) break else: a += 1 else: sh.update_cell(a,1,username) time.sleep(1) sh.update_cell(a,2,firstclass) time.sleep(1) sh.update_cell(a,3,secondclass) time.sleep(1) sh.update_cell(a,4,thirdclass) time.sleep(1) sh.update_cell(a,5,fourthclass) time.sleep(1) sh.update_cell(a,6,fifthclass) time.sleep(1) sh.update_cell(a,7,'ok') time.sleep(1)
Get the user's username from the toot data (this article omits how to get the username) If the username is in the spreadsheet, then if you don't enter the subject name in the cell, enter the username Later, enter the subject name in the cell. If the entry is successful, it will look like this
Output the subject data entered in the spreadsheet to Mastodon
a = 3 while(str(sh.cell(a, 1).value) != ''): if str(sh.cell(a, 1).value) == username: if(sh.cell(a,7).value == 'ok'): mastodon.toot('The timetable is\n1 period is'+sh.cell(a,2).value+'\n2 period is'+sh.cell(a,3).value+'\n3 period is'+sh.cell(a,4).value+'\n4th period'+sh.cell(a,5).value+'\n5 period is'+sh.cell(a,6).value+'\n yawa ~') break else: mastodon.toot('I haven't registered the timetable ~ Have you registered?') break else: a += 1 else: mastodon.toot('It's strange from the timetable ~ Easy to tell ~ ♪\n How to register the timetable is "Princess Maho Today's timetable is 1,subject name,2,subject name3,subject name4,subject name5,subject name」にして空きコマなら無しって書いておくれやす～')
Similar to 3, it is a description that identifies whether the username matches and if there is no username, prompts you to register, and if the username matches and the timetable is registered, the data is acquired and mastodon is used. You did it, Princess Maho tooted the timetable! !!
It is a story that people who do not know python or json at all started making bots and have become able to do so far. Yes. If you want to make a bot! !! If there is a person who says, you can lay the foundation of Mastodon Bot by looking at the article of a certain Bot Tsuyotsuyo Man of C3. https://qiita.com/PigeonsHouse/items/a6a6833e81c8dee384a4
[Introduction] I want to make a Mastodon Bot with Python! 【Beginners】 https://qiita.com/PigeonsHouse/items/a6a6833e81c8dee384a4 I tried to access Google Spread Sheets using Python https://qiita.com/164kondo/items/eec4d1d8fd7648217935