Browse Source

ニジカ動画投稿告知機能追加

main
みてるぞ 2 weeks ago
parent
commit
2e75eabf71
1 changed files with 27 additions and 5 deletions
  1. +27
    -5
      main.py

+ 27
- 5
main.py View File

@@ -58,6 +58,7 @@ def main (


last_posted_at = datetime.now () - timedelta (hours = 6) last_posted_at = datetime.now () - timedelta (hours = 6)
has_got_snack_time = False has_got_snack_time = False
watched_videos = []
while True: while True:
now = datetime.now () now = datetime.now ()


@@ -86,6 +87,20 @@ def main (
parent = records[0]['strong_ref'], parent = records[0]['strong_ref'],
root = records[-1]['strong_ref'])) root = records[-1]['strong_ref']))


for datum in [e for e in get_nico_deerjika ()
if e['contentId'] not in watched_videos]:
watched_videos += [datum['contentId']]

client.send_post (Talk.main (f"""
ニコニコに『{ datum['title'] }』という動画がアップされました。
つけられたタグは「{ '」、「'.join (datum['tags']) }」です。
概要には次のように書かれています:
```html
{ datum['description'] }
```
このことについて、みんなに告知するとともに、ニジカちゃんの感想を教えてください。
"""))

if now.hour == 14 and has_got_snack_time: if now.hour == 14 and has_got_snack_time:
has_got_snack_time = False has_got_snack_time = False


@@ -127,25 +142,32 @@ def get_nico_deerjika ():
'/contents/search') '/contents/search')


now = datetime.now () now = datetime.now ()
base = now - timedelta (hours = 1)


params = { 'q': '伊地知ニジカ', params = { 'q': '伊地知ニジカ',
'targets': 'tagsExact',
'targets': 'tags',
'_sort': '-startTime', '_sort': '-startTime',
'fields': 'contentId,title,description,tags,startTime', 'fields': 'contentId,title,description,tags,startTime',
'_limit': 1,
'_limit': 20,
'jsonFilter': json.dumps ({ 'type': 'or', 'jsonFilter': json.dumps ({ 'type': 'or',
'filters': [{ 'filters': [{
'type': 'range', 'type': 'range',
'field': 'startTime', 'field': 'startTime',
'from': ('%04d-%02d-%02dT00:00:00+09:00'
% (now.year, now.month, now.day)),
'from': ('%04d-%02d-%02dT%02d:%02d:00+09:00'
% (base.year, base.month, base.day,
base.hour, base.minute)),
'to': ('%04d-%02d-%02dT23:59:59+09:00' 'to': ('%04d-%02d-%02dT23:59:59+09:00'
% (now.year, now.month, now.day)), % (now.year, now.month, now.day)),
'include_lower': True }] }) } 'include_lower': True }] }) }


res = requests.get (URL, params = params).json () res = requests.get (URL, params = params).json ()


return res['data'][0] if len (res['data']) > 0 else None
data = []
for datum in res['data']:
datum['tags'] = datum['tags'].split ()
data.append (datum)

return data




if __name__ == '__main__': if __name__ == '__main__':


Loading…
Cancel
Save