Created
June 1, 2019 14:07
-
-
Save PhotonQuantum/bf97cf28e957fe1c4ed8dffc72ccd5ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bottle import route, run, request | |
from requests_futures.sessions import FuturesSession | |
import requests | |
import json | |
client_id = "your_id_here" | |
client_secret = "your_secret_here" | |
username = "your_username_here" | |
password = "your_pass_here" | |
hostname = "your_url_here" | |
def get_session(): | |
param_request = { | |
"grant_type": "password", | |
"client_id": client_id, | |
"client_secret": client_secret, | |
"username": username, | |
"password": password | |
} | |
r = requests.post(hostname + "/oauth/v2/token", data=param_request) | |
token = json.loads(r.text)["access_token"] | |
s = FuturesSession() | |
s.headers.update({"Authorization": "Bearer " + token}) | |
print(token) | |
return s | |
@route('/add') | |
def add(): | |
session = get_session() | |
url = request.query.url | |
param_request = {"url": url} | |
session.post(hostname + "/api/entries.json", data=param_request) | |
return "Post adding scheduled." | |
run(host="localhost", port="8080") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment