add new method that get random sentence
This commit is contained in:
parent
62087c0132
commit
e3c219636d
21
main.py
21
main.py
|
@ -1,23 +1,22 @@
|
||||||
from misskey import Misskey
|
from misskey import Misskey
|
||||||
from setting import instance_address, access_token, google_api_json, spread_sheet_url
|
|
||||||
import gspread
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
from src.setting import instance_address, access_token
|
||||||
|
from src.choose_sentence import chooseSentence
|
||||||
|
from src.generate_sentence import generateSentence
|
||||||
|
|
||||||
# authentication to misskey
|
# authentication to misskey
|
||||||
misskey = Misskey(address=instance_address, i=access_token)
|
misskey = Misskey(address=instance_address, i=access_token)
|
||||||
|
|
||||||
# authentication to google spread sheet
|
|
||||||
gc = gspread.service_account(google_api_json)
|
|
||||||
|
|
||||||
|
|
||||||
def writeRandomSentenceNote():
|
def writeRandomSentenceNote():
|
||||||
# get all sentences
|
choice_methods = [
|
||||||
sheet = gc.open_by_url(spread_sheet_url)
|
chooseSentence,
|
||||||
work_sheet = sheet.get_worksheet(0)
|
generateSentence
|
||||||
sentences = work_sheet.col_values(1)
|
]
|
||||||
|
|
||||||
# choice random sentence
|
# choose method and get sentence
|
||||||
sentence: str = random.choice(sentences)
|
sentence: str = random.choice(choice_methods)()
|
||||||
|
|
||||||
# change newline-character to be valid
|
# change newline-character to be valid
|
||||||
sentence = sentence.replace("\\n", "\n")
|
sentence = sentence.replace("\\n", "\n")
|
||||||
|
|
16
src/choose_sentence.py
Normal file
16
src/choose_sentence.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
from src.setting import google_api_json, spread_sheet_url
|
||||||
|
import gspread, random
|
||||||
|
|
||||||
|
# authentication to google spread sheet
|
||||||
|
gc = gspread.service_account(google_api_json)
|
||||||
|
|
||||||
|
|
||||||
|
# choose random sentence in google spread sheet
|
||||||
|
def chooseSentence() -> str:
|
||||||
|
# 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
|
||||||
|
return random.choice(sentences)
|
103
src/generate_sentence.py
Normal file
103
src/generate_sentence.py
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
import random
|
||||||
|
|
||||||
|
# sentence components
|
||||||
|
_subjects = [
|
||||||
|
"내가",
|
||||||
|
"고양이가",
|
||||||
|
"강아지가",
|
||||||
|
"키위가",
|
||||||
|
"코끼리가",
|
||||||
|
"삐삐쀼쀼가",
|
||||||
|
"물고기가",
|
||||||
|
"사카밤바스피스가",
|
||||||
|
"툿친이",
|
||||||
|
"일론 머스크가",
|
||||||
|
"카피바라가",
|
||||||
|
"멜론이",
|
||||||
|
"김정은이",
|
||||||
|
"타임라인이",
|
||||||
|
"도파민이",
|
||||||
|
"상사가",
|
||||||
|
"블롭캣이",
|
||||||
|
"아기가"
|
||||||
|
]
|
||||||
|
|
||||||
|
_modifiers = [
|
||||||
|
"놀라운",
|
||||||
|
"거대한",
|
||||||
|
"하와와한",
|
||||||
|
"귀여운",
|
||||||
|
"말랑말랑한",
|
||||||
|
"무서운",
|
||||||
|
"더러운",
|
||||||
|
"최고의",
|
||||||
|
"최애의",
|
||||||
|
"맛있는",
|
||||||
|
"복잡한",
|
||||||
|
"반짝반짝한",
|
||||||
|
"뿌슝빠슝한",
|
||||||
|
"엘렐레한",
|
||||||
|
"작은",
|
||||||
|
"작고 하찮은",
|
||||||
|
"둔한",
|
||||||
|
"날렵한",
|
||||||
|
"느린",
|
||||||
|
"빠른"
|
||||||
|
]
|
||||||
|
|
||||||
|
_objects = [
|
||||||
|
"서버장을",
|
||||||
|
"블롭캣을",
|
||||||
|
"키보드를",
|
||||||
|
"고양이를",
|
||||||
|
"탕후루를",
|
||||||
|
"지뢰를",
|
||||||
|
"삐삐쀼쀼를",
|
||||||
|
"생체 서버를",
|
||||||
|
"학교를",
|
||||||
|
"트위터를",
|
||||||
|
"아이폰을",
|
||||||
|
"리눅스를",
|
||||||
|
"서버를",
|
||||||
|
"멸치를",
|
||||||
|
"연필을",
|
||||||
|
"ActiveX를",
|
||||||
|
"턱스를",
|
||||||
|
"비밀번호를",
|
||||||
|
"돈을",
|
||||||
|
"통장을",
|
||||||
|
"집을",
|
||||||
|
"회사를"
|
||||||
|
]
|
||||||
|
|
||||||
|
_verbs = [
|
||||||
|
"담궜다",
|
||||||
|
"먹었다",
|
||||||
|
"쓰다듬었다",
|
||||||
|
"만들었다",
|
||||||
|
"사랑했다",
|
||||||
|
"던졌다",
|
||||||
|
"요리했다",
|
||||||
|
"찼다",
|
||||||
|
"구웠다",
|
||||||
|
"사냥했다",
|
||||||
|
"터뜨렸다",
|
||||||
|
"반으로 갈랐다",
|
||||||
|
"구부려트렸다",
|
||||||
|
"삭제했다",
|
||||||
|
"촬영했다",
|
||||||
|
"키웠다",
|
||||||
|
"잡아먹었다",
|
||||||
|
"눌렀다",
|
||||||
|
"서버로 만들었다"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# choose random sentence components and generate sentence using them
|
||||||
|
def generateSentence():
|
||||||
|
subject = random.choice(_subjects)
|
||||||
|
modifier = random.choice(_modifiers)
|
||||||
|
object = random.choice(_objects)
|
||||||
|
verb = random.choice(_verbs)
|
||||||
|
|
||||||
|
return f"{subject} {modifier} {object} {verb}."
|
Loading…
Reference in a new issue