This commit is contained in:
sunwoo1524 2023-12-03 23:01:55 +09:00
commit f871121f75
5 changed files with 71 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
venv/
setting.py
google_api.json
__pycache__/

31
README.md Normal file
View file

@ -0,0 +1,31 @@
# Misskey Random Sentence Bot
## How to run
1. clone repo
2. make venv
```
python3 -m venv venv
source ./venv/bin/activate
```
3. install modules
```
pip install -r requirements.txt
```
4. change setting
```
# copy example setting file
cp setting_example.py setting.py
# edit setting file
vim setting.py
```
- `instance_address`: address of misskey instance that your bot will run
- `access_token`: API access token of your bot account
- `google_api_json`: your google api access json file
- `spread_sheet_url`: URL of spread sheet that include sentences as:
![](https://r2.worldc.one/media/fa04a9ba-e50e-4b63-81c3-73416f1481b7.webp)
5. RUN
```
python main.py
```

30
main.py Normal file
View file

@ -0,0 +1,30 @@
from misskey import Misskey
from setting import instance_address, access_token, google_api_json, spread_sheet_url
import gspread
import random
# authentication to misskey
misskey = Misskey(address=instance_address, i=access_token)
# authentication to google spread sheet
gc = gspread.service_account(google_api_json)
def writeRandomSentenceNote():
# get all sentences
sheet = gc.open_by_url(spread_sheet_url)
work_sheet = sheet.get_worksheet(0)
sentences = work_sheet.col_values(1)
# choice random sentence
sentence = random.choice(sentences)
# write note
random_sentence_note = misskey.notes_create(text=sentence)
note_id = random_sentence_note["createdNote"]["id"]
note_text = random_sentence_note["createdNote"]["text"]
print(f"{note_id} | {note_text}")
if __name__ == "__main__":
writeRandomSentenceNote()

2
requirements.txt Normal file
View file

@ -0,0 +1,2 @@
Misskey.py
gspread

4
setting_example.py Normal file
View file

@ -0,0 +1,4 @@
instance_address = "your_misskey_instance.tld"
access_token = "your_misskey_api_access_token"
google_api_json = "your_google_api_json_file.json" # Absolute path is recommended.
spread_sheet_url = "your_google_spread_sheet_url"