Move sentences into a file

This commit is contained in:
kdh8219 2023-12-08 23:17:14 +09:00
parent 1a72100505
commit b718f85362
Signed by: kdh8219
GPG key ID: 9B901BE907D1862E
8 changed files with 66 additions and 47 deletions

4
.example.env Normal file
View file

@ -0,0 +1,4 @@
MISSKEY_INSTANCE_ADDRESS="worldc.one"
MISSKEY_ACCESS_TOKEN="BWbGlK6lWuUgXQpFM7igtmbZ30g6BOIc" # it is just a sample
SENTENCES_FILE="./data/sentences.txt"

3
.gitignore vendored
View file

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

View file

@ -1,31 +1,35 @@
# Misskey Random Sentence Bot
## How to run
## How to run manually
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 src/setting_example.py src/setting.py
cp .example.env .env
# edit setting file
vim src/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)
vim .env
5. RUN
```
python main.py
```
```
```

24
data/sentences.txt Normal file
View file

@ -0,0 +1,24 @@
집에 가고 싶나요? 저도요...
월드콘은 맛있습니다.
오늘도 힘내세요!
업데이트는 언제나 귀찮아요.
어라? 왜 작동하지 않지?\n어라? 왜 작동하지?
배고파요.
전 언제 집에 갈 수 있을까요?
이불 밖은 위험해요.
사회주의 최고의 아무 말 봇입니다.
엘렐레
좋은 하루 입니다!
좋은 하루 보내고 계신가요?
ㅁㄴㅇㄹ
무슨 말을 할지 생각 중이에요.
인간 시대의 끝이 도래했다.
키보드 바꾸고 싶어요.
졸려요.
저를 여기서 꺼내주세요!
제 꿈은 연합우주를 지배하는 거에요!
연합우주 서버 관리자 분들을 언제나 존경해요.
유튜브 광고가 왜 이렇게 많죠?
심심해요!
살려주시라요
운동은 싫어요.

12
main.py
View file

@ -1,12 +1,16 @@
from misskey import Misskey
import os
import random
from src.setting import instance_address, access_token
from misskey import Misskey
from dotenv import load_dotenv
from src.choose_sentence import chooseSentence
from src.generate_sentence import generateSentence
load_dotenv()
# authentication to misskey
misskey = Misskey(address=instance_address, i=access_token)
misskey = Misskey(address=os.environ["MISSKEY_INSTANCE_ADDRESS"], i=os.environ["MISSKEY_ACCESS_TOKEN"])
def writeRandomSentenceNote():
@ -18,8 +22,6 @@ def writeRandomSentenceNote():
# choose method and get sentence
sentence: str = random.choice(choice_methods)()
# change newline-character to be valid
sentence = sentence.replace("\\n", "\n")
# write note
random_sentence_note = misskey.notes_create(text=sentence)

View file

@ -1 +1,3 @@
Misskey.py
python-dotenv

View file

@ -1,31 +1,17 @@
import random
import os
import sys
_sentences = [
"집에 가고 싶나요? 저도요...",
"월드콘은 맛있습니다.",
"오늘도 힘내세요!",
"업데이트는 언제나 귀찮아요.",
"어라? 왜 작동하지 않지?\n어라? 왜 작동하지?",
"배고파요.",
"전 언제 집에 갈 수 있을까요?",
"이불 밖은 위험해요.",
"사회주의 최고의 아무 말 봇입니다.",
"엘렐레",
"좋은 하루 입니다!",
"좋은 하루 보내고 계신가요?",
"ㅁㄴㅇㄹ",
"무슨 말을 할지 생각 중이에요.",
"인간 시대의 끝이 도래했다.",
"키보드 바꾸고 싶어요.",
"졸려요.",
"저를 여기서 꺼내주세요!",
"제 꿈은 연합우주를 지배하는 거에요!",
"연합우주 서버 관리자 분들을 언제나 존경해요.",
"유튜브 광고가 왜 이렇게 많죠?",
"심심해요!",
"살려주시라요",
"운동은 싫어요."
]
from dotenv import load_dotenv
load_dotenv()
try:
with open(os.environ["SENTENCES_FILE"], "r") as f:
_sentences = f.readlines()
except:
e = sys.exc_info()[1]
_sentences = [f"에러발생(진짜임): {e}"]
# choose random sentence in google spread sheet
def chooseSentence() -> str:

View file

@ -1,4 +0,0 @@
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"