Skip to content

Commit

Permalink
Merge pull request #1 from MiyabiTane/add_emoji_unitree_email
Browse files Browse the repository at this point in the history
  • Loading branch information
tkmtnt7000 authored May 17, 2022
2 parents bdd220d + d2c3bcf commit f57b932
Showing 1 changed file with 87 additions and 1 deletion.
88 changes: 87 additions & 1 deletion jsk_unitree_robot/jsk_unitree_startup/scripts/launch-email.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import random
import subprocess
import emoji
import sys
if sys.version_info.major == 2:
import urllib2
Expand Down Expand Up @@ -95,6 +96,89 @@ def get_weather_forecast(self, lang='en'):

return forecast_text

def add_emoji(self, mode):
"""
0: 普通, 1: 喜び, 2: 安心, 3: 悪巧み, 4: 驚き, 5: 悲しみ, 6: 怒り, 7: 照れ,
8: 恐怖, 9: 好き, 10: ウインク・おふざけ, 11: 退屈, 12: 混乱
ref: https://www.webfx.com/tools/emoji-cheat-sheet/
"""
dic = {0: ":neutral_face:", 1: ":smile:", 2: ":relieved:", 3: ":smirk:" ,
4: ":astonished:", 5: ":cry:", 6: ":angry:", 7: ":flushed:",
8: ":scream:", 9: ":heart_eyes:", 10: ":wink:", 11: ":sleepy:", 12: ":sweat:"}

return emoji.emojize(dic[mode], language='alias')

def get_fortune(self):
"""
Get tips from horoscope
Return:
message : str
"""
def add_comment_rank(rank):
if rank == 1:
message = "すごい、1位だ" + self.add_emoji(4)
elif rank <= 3:
message = str(rank) + "位!いい感じ" + self.add_emoji(1)
elif rank == 12:
message = "最下位..." + self.add_emoji(5) + "ラッキーアイテムをチェックしなきゃ!!"
else:
message = str(rank) + "位かぁ。そこそこかな" + self.add_emoji(0)
return " " + message

def add_comment_love(point):
if point >= 9:
message = "出会いを求めてお散歩しちゃおっかな" + self.add_emoji(9)
elif point >= 6:
message = "気になってるあの子に会えちゃうかも" + self.add_emoji(7)
elif point <= 3:
message = "こんなの信じないぞ" + self.add_emoji(6)
else:
message = "平凡な一日になりそう..." + self.add_emoji(11)
return " " + message

def add_comment_money(point):
if point >= 9:
message = "今日はお買い物しちゃおうかな" + self.add_emoji(10)
elif point <= 3:
message = "お金のつかい過ぎには気をつけよう..." + self.add_emoji(8)
else:
message = "今日は何事もなさそうかな" + self.add_emoji(2)
return " " + message

def add_comment_business(point):
if point >= 7:
message = "研究頑張ったら良いことあるかも" + self.add_emoji(1)
elif point >= 4:
message = "いいのか悪いのか分からないなぁ" + self.add_emoji(12)
else:
message = "今日は研究さぼっちゃおうかな〜" + self.add_emoji(3)
return " " + message

url = 'https://fortune.yahoo.co.jp/12astro/sagittarius'
if sys.version_info.major == 2:
response = urllib2.urlopen(url)
else:
response = request.urlopen(url)
soup = BeautifulSoup(response, "html.parser")
fortune = soup.find('div', id="jumpdtl").find_all('td')
f_contents = soup.find('div', class_="yftn12a-md48").find_all('dd')[0].contents[0]
rank = fortune[-5].contents[0].contents[0][0:2]
point_overall = fortune[-4].contents[0].attrs['alt']
point_love = fortune[-3].contents[0].attrs['alt']
point_money = fortune[-2].contents[0].attrs['alt']
point_business = fortune[-1].contents[0].attrs['alt']
message = "今日の星座占い:いて座の運勢は【" + rank + "】" + add_comment_rank(int(rank[0])) + "\n"
message += f_contents + "\n"
message += "だって!\n"
message += "\n"
message += "総合運: " + point_overall + "\n"
message += "恋愛運: " + point_love + add_comment_love(int(point_love[-2])) + "\n"
message += "金運: " + point_money + add_comment_money(int(point_money[-2])) + "\n"
message += "仕事運: " + point_business + add_comment_business(int(point_business[-2])) + "\n"
response.close()

return message

def send_mail(self):
"""
Send mail with mailutils
Expand All @@ -116,13 +200,15 @@ def send_mail(self):
message += "詳細: {} \\n".format(detail_url)
message += "\\n"

message += self.get_fortune()
message += "\\n"

# echo -e option is necessary in raspberry pi
cmd = "echo -e '{}'".format(message)
cmd += " | /usr/bin/mail -s '{}' -r {} {}".format(
mail_title, sender_address, receiver_address)
exit_code = subprocess.call(cmd, shell=True)


if __name__ == '__main__':
RobotLaunchEmail = RobotLaunchEmail()
RobotLaunchEmail.send_mail()

0 comments on commit f57b932

Please sign in to comment.