-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapod.py
More file actions
executable file
·40 lines (32 loc) · 1.27 KB
/
apod.py
File metadata and controls
executable file
·40 lines (32 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 27 16:01:46 2019
@author: edombek
"""
#скрипт для постиинга, прописать на автозапус раз в день)
import json
conf = json.loads(open('config.json').read())
import vk_api
#получаем ид группы от имени группы
vk_session = vk_api.VkApi(token = conf['token'])
vk = vk_session.get_api()
group_id = vk.groups.getById()[0]['id']
#логин от имени админа группы
vk_session = vk_api.VkApi(token = conf['user_token'])
vk = vk_session.get_api()
#nasa apod
import urllib.request
resp = json.loads(urllib.request.urlopen('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY').read())
urllib.request.urlretrieve(resp['hdurl'], 'temp.jpg')
upload = vk_api.VkUpload(vk_session)
photo = upload.photo_wall(photos='temp.jpg', group_id = group_id)
photo = 'photo{}_{}_{}'.format(photo[0]['owner_id'], photo[0]['id'], photo[0]['access_key'])
print(resp)
try:
resp['copyright']
except:
resp['copyright'] = None
text = 'Astronomy Picture of the Day (apod.nasa.gov)\n\n{}\n\n{}\n\n©{}'.format(resp['title'], resp['explanation'], resp['copyright'])
#постим
vk.wall.post(message=text, owner_id = -group_id, from_group = 1, attachments = photo)