2.0.0
This commit is contained in:
parent
09ca61e016
commit
99a065b81b
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
Включает в себя `systemd` юнит.
|
Включает в себя `systemd` юнит.
|
||||||
|
|
||||||
![preview](https://raw.githubusercontent.com/iiiypuk/vk0nline/master/asset/.preview.png)
|
![preview](https://raw.githubusercontent.com/iiiypuk/vk0nline/master/.preview.png)
|
||||||
|
|
||||||
## Установка
|
## Установка
|
||||||
Активировать автоматический запуск сессии пользователя
|
Активировать автоматический запуск сессии пользователя
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: vk0nline
|
name: vk0nline
|
||||||
version: 0.1.0
|
version: 2.0.0
|
||||||
|
|
||||||
authors:
|
authors:
|
||||||
- Alexander Popov <iiiypuk@iiiypuk.me>
|
- Alexander Popov <iiiypuk@iiiypuk.me>
|
||||||
|
|
|
@ -1,36 +1,56 @@
|
||||||
require "json"
|
require "json"
|
||||||
require "crest"
|
require "crest"
|
||||||
|
|
||||||
# TODO: Write documentation for `Src`
|
begin # JSON::ParseException
|
||||||
module Src
|
|
||||||
VERSION = "0.1.0"
|
|
||||||
|
|
||||||
json = File.open("config.json") do |file|
|
json = File.open("config.json") do |file|
|
||||||
JSON.parse(file)
|
JSON.parse(file)
|
||||||
end
|
end
|
||||||
|
rescue
|
||||||
|
puts "Parse config.json error"
|
||||||
|
|
||||||
# TODO: Get accessToken
|
exit
|
||||||
if json["accessToken"] == nil
|
end
|
||||||
puts "Get accessToken"
|
|
||||||
|
|
||||||
token_url = "https://oauth.vk.com/authorize?client_id=#{json["appID"].as_i}&redirect_uri=vk.com&response_type=token&display=mobile&v=5.131&revoke=1&state=01010&scope=offline"
|
def get_access_token(appId : Int32)
|
||||||
|
puts "Open this page, and save token to config.json\n\n"
|
||||||
|
|
||||||
puts token_url
|
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 "Open this page, and save token to config.json"
|
puts token_url
|
||||||
else
|
end
|
||||||
# TODO: If return 1 == COMPLETE
|
|
||||||
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)
|
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 }
|
||||||
|
)
|
||||||
|
|
||||||
if status["response"] == 1
|
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 # Missing hash key
|
||||||
|
if status["response"] == 1
|
||||||
puts "Complete!"
|
puts "Complete!"
|
||||||
end
|
end
|
||||||
|
rescue
|
||||||
|
# execute if an exception is raised
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
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()
|
|
Loading…
Reference in New Issue