This commit is contained in:
Alexander Popov 2019-05-04 02:09:46 +03:00
commit 15efeb086a
8 changed files with 135 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
config.json

BIN
.preview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

24
LICENSE Normal file
View File

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org>

35
README.md Normal file
View File

@ -0,0 +1,35 @@
# vk.com set online status service
Набор инструментов для поддержания твоего статуса в социальной сети Vk.com __"Онлайн"__
![preview](https://raw.githubusercontent.com/iiiypuk/vk0nline/master/.preview.png)
Набор включает в себя скрипт на `Python` и юнит `systemd`.
## Установка:
+ Скачать и распаковать набор инструметов, например в `/home/user_name/.vk0nline`
+ Создать директорию для юнитов systemd: `mkdir -p ~/.config/systemd/user`
и перейти в неё: `cd ~/.config/systemd/user`
+ Сделать символические ссылки на сервис и таймер:
```
ln -s /home/user_name/.vk0nline/systemd/user/vk0nline.service .
ln -s /home/user_name/.vk0nline/systemd/user/vk0nline.timer .
```
+ Изменить настройки скрипта и сделать его исполняемым:
```
cd ~/.vk0nline/
mv config.json.example config.json
chmod 755 ./vk0nline.py
edit config.json
```
+ Прописать полный путь к файлу конфигурации в скрипте:
```python
# EDIT IT
with open('./config.json', 'r', encoding='utf-8') as f:
```
+ Прописать полный путь к файлу скрипта в сервисе systemd:
`edit ~/.config/systemd/user/vk0nline.service`
`ExecStart=/full/path/to/vk0nline.py`
+ Активируем и запускаем скрипт:
```
systemctl start vk0nline.service --user
systemctl enable vk0nline.timer --user
systemctl start vk0nline.timer --user
```

7
config.json.example Normal file
View File

@ -0,0 +1,7 @@
{
"clientId": 1,
"secureKey": "",
"serviceKey": "",
"accessToken": "",
"userIds": ""
}

View File

@ -0,0 +1,6 @@
[Unit]
Description=vk.com set online status service
[Service]
Type=simple
ExecStart=/full/path/to/vk0nline.py

View File

@ -0,0 +1,11 @@
[Unit]
Description=vk.com set online status timer
[Timer]
OnBootSec=1min
OnUnitActiveSec=4min
Persistent=true
Unit=vk0nline.service
[Install]
WantedBy=multi-user.target

51
vk0nline.py Normal file
View File

@ -0,0 +1,51 @@
#!/usr/bin/env python3
import json
import requests
from datetime import datetime
__author__ = 'Alexander Popov'
__copyright__ = '2019 by iiiypuk'
__credits__ = ['Alexander Popov']
__license__ = 'Unlicense'
__version__ = '1.0.0'
__maintainer__ = 'Alexander Popov'
__email__ = 'iiiypuk@fastmail.fm'
__status__ = 'Production'
# EDIT IT
with open('./config.json', 'r', encoding='utf-8') as f:
_C = json.load(f)
def getStatus():
response = requests.get('https://api.vk.com/method/users.get?' + \
'fields=online,last_seen&v=5.95' + \
'&access_token={key}&user_ids={user}'.format(
key=_C['serviceKey'], user=_C['userIds']))
userLoginTime = json.loads(response.content.decode('utf-8'))['response'][0]['last_seen']['time']
userOnline = json.loads(response.content.decode('utf-8'))['response'][0]['online']
return([userOnline, userLoginTime])
def setOnline():
response = requests.get('https://api.vk.com/method/account.setOnline' + \
'?voip=0&v=5.95&access_token={key}'.format(key=_C['accessToken']) + \
'&user_ids={user}'.format(user=_C['userIds']))
content = json.loads(response.content.decode('utf-8'))
if 'error' in content:
if 5 == content['error']['error_code']: # User authorization failed
print('User authorization failed.\nOpen this link in browser, and copy access token.')
print('https://oauth.vk.com/authorize?client_id={appid}'.format(appid=_C['clientId']) + \
'&redirect_uri=vk.com&display=mobile&response_type=' + \
'token&v=5.95&revoke=1&state=01010&scope=offline')
else:
print('Error: {}.'.format(content['error']['error_code']))
elif 'response' in content:
if 1 == content['response']:
print('Ok!')
onlineStatus, lastSeen = getStatus()
print(onlineStatus, datetime.fromtimestamp(lastSeen).strftime('%Y-%m-%d %H:%M:%S'))
if __name__ == "__main__": setOnline()