Skip to content

Instantly share code, notes, and snippets.

@blackjack4494
Last active June 28, 2021 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackjack4494/3dfc0aa2b8920cc17ce9e70174620fda to your computer and use it in GitHub Desktop.
Save blackjack4494/3dfc0aa2b8920cc17ce9e70174620fda to your computer and use it in GitHub Desktop.
Viki.com API Login
import requests
import sys
import getpass
import time
import hashlib
import hmac
import json
_API_QUERY_TEMPLATE = '/v4/%sapp=%s&t=%s&site=www.viki.com'
_API_URL_TEMPLATE = 'https://api.viki.io%s&sig=%s'
_APP = '100000a' # '100005a'
_APP_VERSION = '2.2.5.1428709186'
_APP_SECRET = 'MM_d*yP@`&1@]@!AVrXf_o-HVEnoTnm$O-ti4[G~$JDI/Dc-&piU&z&5.;:}95=Iad'
# new _APP_SECRET = 'd96704b180208dbb2efa30fe44c48bd8690441af9f567ba8fd710a72badc85198f7472'
_token = None
def cred_login():
user = input("User: ")
password = getpass.getpass()
return login(user=user, password=password)
def login(user=None, password=None, login_json=None):
if user is None:
if login_json is None:
print("provide either user/pass or login json")
return
else:
login_form = login_json
else:
login_form_cred = {
"login_id": user,
"password": password,
}
login_form = login_form_cred
path = 'sessions.json'
path += '?' if '?' not in path else '&'
timestamp = ''
if not timestamp:
timestamp = int(time.time())
query = _API_QUERY_TEMPLATE % (path, _APP, timestamp)
sig = hmac.new(
_APP_SECRET.encode('ascii'),
query.encode('ascii'),
hashlib.sha1
).hexdigest()
url = _API_URL_TEMPLATE % (query, sig)
r = requests.post(url, json=login_form)
return r.json().get("token")
login_form = {
"login_id": "USERNAME",
"password": "SECRET",
}
# input user and password in terminal
print(cred_login())
# provide a login_form ~ useful for automated testing
#print(login(login_form))
# provide user and password directly ~ useful for automated testing
#print(login("USERNAME", "SECRET"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment