Compare commits
7 Commits
python-old
...
2.0.0
Author | SHA1 | Date | |
---|---|---|---|
7e77d85988 | |||
ff9f7730c8 | |||
9c774e0460 | |||
becda71b3a | |||
1c3f743d5c | |||
99a065b81b | |||
09ca61e016 |
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@ -0,0 +1,9 @@
|
||||
root = true
|
||||
|
||||
[*.cr]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = true
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -1 +1,7 @@
|
||||
/docs/
|
||||
/lib/
|
||||
/bin/
|
||||
/.shards/
|
||||
*.dwarf
|
||||
|
||||
config.json
|
||||
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
0
install.sh → .trash/install.sh
Normal file → Executable file
0
install.sh → .trash/install.sh
Normal file → Executable file
6
.travis.yml
Normal file
6
.travis.yml
Normal file
@ -0,0 +1,6 @@
|
||||
language: crystal
|
||||
|
||||
# Uncomment the following if you'd like Travis to run specs and check code formatting
|
||||
# script:
|
||||
# - crystal spec
|
||||
# - crystal tool format --check
|
37
LICENSE
37
LICENSE
@ -1,24 +1,21 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
The MIT License (MIT)
|
||||
|
||||
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.
|
||||
Copyright (c) 2021 Alexander Popov <iiiypuk@iiiypuk.me>
|
||||
|
||||
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.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
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.
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
For more information, please refer to <http://unlicense.org>
|
||||
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 OR COPYRIGHT HOLDERS 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.
|
||||
|
36
README.md
36
README.md
@ -1,11 +1,13 @@
|
||||
# service for set status online on vk.com
|
||||
Скрипт для поддержания статуса __Онлайн__ в социальной сети Vk.com
|
||||
включает в себя `Python` скрипт `systemd` юнит.
|
||||

|
||||
# vk0nline
|
||||
Утилита для поддержания статуса __Онлайн__ в социальной сети Vk.com.
|
||||
|
||||
## Установка:
|
||||
+ Активировать автоматический запуск сессии пользователя
|
||||
```console
|
||||
Включает в себя `systemd` юнит.
|
||||
|
||||

|
||||
|
||||
## Установка
|
||||
Активировать автоматический запуск сессии пользователя
|
||||
```bash
|
||||
# Изменить параметр ReadWritePaths=/etc /run /var/lib/systemd/linger
|
||||
nano /usr/lib/systemd/system/systemd-logind.service
|
||||
# Перезапустить сервисы
|
||||
@ -13,11 +15,21 @@ systemctl daemon-reload
|
||||
# Активировать пользователя
|
||||
mkdir /var/lib/systemd/linger
|
||||
loginctl enable-linger $USER
|
||||
|
||||
Подготавливаем рабочую директорию
|
||||
mkdir -p /home/$USER/.local/share/emilecok/vk0nline/
|
||||
wget https://github.com/iiiypuk/vk0nline/blob/master/config.json.example -O /home/$USER/.local/share/emilecok/vk0nline/config.json
|
||||
wget $BINARY -O /home/$USER/.local/share/emilecok/vk0nline/vk0nline.x86_64-lnx
|
||||
chmod +x /home/$USER/.local/share/emilecok/vk0nline/vk0nline.x86_64-lnx
|
||||
|
||||
# Заполняем конфигурационный файл, поля appID и userIds
|
||||
vi /home/$USER/.local/share/emilecok/vk0nline/config.json
|
||||
|
||||
# Запускаем, получаем accessToken и запускаем ещё раз
|
||||
/home/$USER/.local/share/emilecok/vk0nline/vk0nline.x86_64-lnx
|
||||
```
|
||||
|
||||
+ Скачать и запустить установщик
|
||||
```console
|
||||
curl -Lsk https://raw.githubusercontent.com/iiiypuk/vk0nline/master/install.sh | sh
|
||||
## Systemd
|
||||
```bash
|
||||
...
|
||||
```
|
||||
|
||||
+ Следовать инструкциям установщика
|
||||
|
8
build.sh
Executable file
8
build.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
if ! [[ -d ./bin/ ]]
|
||||
then
|
||||
mkdir bin
|
||||
fi
|
||||
|
||||
crystal build --progress --no-debug --release src/vk0nline.cr -o bin/vk0nline.x86_64-lnx
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"clientId": 1,
|
||||
"secureKey": "",
|
||||
"serviceKey": "",
|
||||
"accessToken": ""
|
||||
"appID": 6954184,
|
||||
"userIds": 69040735,
|
||||
"accessToken": null
|
||||
}
|
||||
|
14
shard.lock
Normal file
14
shard.lock
Normal file
@ -0,0 +1,14 @@
|
||||
version: 2.0
|
||||
shards:
|
||||
crest:
|
||||
git: https://github.com/mamantoha/crest.git
|
||||
version: 0.27.0
|
||||
|
||||
http-client-digest_auth:
|
||||
git: https://github.com/mamantoha/http-client-digest_auth.git
|
||||
version: 0.6.0
|
||||
|
||||
http_proxy:
|
||||
git: https://github.com/mamantoha/http_proxy.git
|
||||
version: 0.8.0
|
||||
|
17
shard.yml
Normal file
17
shard.yml
Normal file
@ -0,0 +1,17 @@
|
||||
name: vk0nline
|
||||
version: 2.0.0
|
||||
|
||||
authors:
|
||||
- Alexander Popov <iiiypuk@iiiypuk.me>
|
||||
|
||||
targets:
|
||||
src:
|
||||
main: src/src.cr
|
||||
|
||||
dependencies:
|
||||
crest:
|
||||
github: mamantoha/crest
|
||||
|
||||
crystal: 1.0.0
|
||||
|
||||
license: MIT
|
56
src/vk0nline.cr
Normal file
56
src/vk0nline.cr
Normal file
@ -0,0 +1,56 @@
|
||||
require "json"
|
||||
require "crest"
|
||||
|
||||
begin # JSON::ParseException
|
||||
json = File.open("config.json") do |file|
|
||||
JSON.parse(file)
|
||||
end
|
||||
rescue
|
||||
puts "Parse config.json error"
|
||||
|
||||
exit
|
||||
end
|
||||
|
||||
def get_access_token(appId : Int32)
|
||||
puts "Open this page, and save token to config.json\n\n"
|
||||
|
||||
token_url = "https://oauth.vk.com/authorize?client_id="\
|
||||
"#{appId}&redirect_uri=vk.com&response_type=token"\
|
||||
"&display=mobile&v=5.131&revoke=1&state=01010&scope=offline"
|
||||
|
||||
puts token_url
|
||||
end
|
||||
|
||||
if json["accessToken"] == nil
|
||||
get_access_token(json["appID"].as_i)
|
||||
else
|
||||
response = Crest.get(
|
||||
"https://api.vk.com/method/account.setOnline",
|
||||
params: { :voip => "0", :v => "5.131",
|
||||
:access_token => json["accessToken"].as_s,
|
||||
:user_ids => json["userIds"].as_i }
|
||||
)
|
||||
|
||||
status = JSON.parse(response.body)
|
||||
|
||||
begin # Missing hash key
|
||||
if status["error"]
|
||||
puts status["error"]["error_msg"]
|
||||
puts "Error code #{status["error"]["error_code"]}"
|
||||
|
||||
puts "---"
|
||||
|
||||
get_access_token(json["appID"].as_i)
|
||||
end
|
||||
rescue
|
||||
# execute if an exception is raised
|
||||
end
|
||||
|
||||
begin # Status set
|
||||
if status["response"] == 1
|
||||
puts "Complete!"
|
||||
end
|
||||
rescue
|
||||
# execute if an exception is raised
|
||||
end
|
||||
end
|
@ -4,7 +4,7 @@ After=network.target network-online.target nss-lookup.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/home/USERNAME/.local/share/emilecok/vk0nline/vk0nline.py
|
||||
ExecStart=/home/USERNAME/.local/share/emilecok/vk0nline/vk0nline.x86_64-lnx
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
|
69
vk0nline.py
69
vk0nline.py
@ -1,69 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import requests
|
||||
from datetime import datetime
|
||||
import getpass
|
||||
import sys
|
||||
|
||||
__author__ = 'Alexander Popov'
|
||||
__copyright__ = '2019 by iiiypuk'
|
||||
__credits__ = ['Alexander Popov']
|
||||
__license__ = 'Unlicense'
|
||||
__version__ = '1.0.3'
|
||||
__maintainer__ = 'Alexander Popov'
|
||||
__email__ = 'iiiypuk@fastmail.fm'
|
||||
__status__ = 'Production'
|
||||
|
||||
username = getpass.getuser()
|
||||
with open('/home/{user}/.config/emilecok/vk0nline/config.json'
|
||||
.format(user=getpass.getuser()), '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['clientId']))
|
||||
userLoginTime = json.loads(response.content.decode('utf-8'))
|
||||
userLoginTime = userLoginTime['response'][0]['last_seen']['time']
|
||||
userOnline = json.loads(response.content.decode('utf-8'))
|
||||
userOnline = userOnline['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}&user_ids={user}'
|
||||
.format(user=_C['clientId'],
|
||||
key=_C['accessToken']))
|
||||
content = json.loads(response.content.decode('utf-8'))
|
||||
|
||||
if 'error' in content:
|
||||
# User authorization failed
|
||||
if 5 == content['error']['error_code']:
|
||||
print('User authorization failed.\n',
|
||||
'Open this link in browser, and copy access token.')
|
||||
print('https://oauth.vk.com/authorize?client_id={appid}'
|
||||
'&redirect_uri=vk.com&display=mobile&response_type=token'
|
||||
'&v=5.95&revoke=1&state=01010&scope=offline'
|
||||
.format(appid=_C['clientId']))
|
||||
else:
|
||||
print('Error: {}.'.format(content['error']['error_code']))
|
||||
elif 'response' in content:
|
||||
if 1 == content['response']:
|
||||
onlineStatus, lastSeen = getStatus()
|
||||
lastSeen = datetime.fromtimestamp(lastSeen) \
|
||||
.strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
if 0 == onlineStatus:
|
||||
print('Not successful.')
|
||||
sys.exit(1)
|
||||
|
||||
print('Last online', lastSeen)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
setOnline()
|
Reference in New Issue
Block a user