Compare commits

..

5 commits

Author SHA1 Message Date
ffbe4db922
added home.html 2018-11-05 09:17:28 +10:00
14fce1a260
noted that it's not done yet 2018-11-05 09:04:33 +10:00
d03514fa75
renamed main.py to run.py, minor changes 2018-11-05 09:02:26 +10:00
820059c95f
example url 2018-11-04 22:19:38 +10:00
85fc4ca5ca
js reminder, fetch auth stuff 2018-11-04 21:36:25 +10:00
7 changed files with 66 additions and 17 deletions

View file

@ -1,2 +1,4 @@
# Curious-Greg # Curious-Greg
Curious Cat Mastodon crossposter thingy c: Curious Cat Mastodon crossposter thingy c:
it's not done yet uwu

View file

@ -7,3 +7,4 @@
import requests, sqlite3, json import requests, sqlite3, json
from mastodon import Mastodon from mastodon import Mastodon
cfg = json.load(open('meta.json'))

View file

@ -35,8 +35,6 @@ async function ajax(url) { //must be called from an async function! use 'await',
async function cont() { async function cont() {
url = dgel('instance-input').value; url = dgel('instance-input').value;
if (url.substr(0,8) != "https://") { j = await ajax('/internal/auth_a?url=' + url)
url = "https://" + url console.log(j)
}
} }

View file

@ -46,6 +46,7 @@ button {
border-radius:2px; border-radius:2px;
padding:10px 25px; padding:10px 25px;
transition:0.2s all ease-in; transition:0.2s all ease-in;
cursor: pointer;
} }
button:hover{ button:hover{
background-color:#2b90d9; background-color:#2b90d9;

24
templates/home.html Normal file
View file

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Curious Greg - Home</title>
<link rel='stylesheet' type='text/css' href="{{ url_for('static', filename='style.css') }}" />
<script type="text/javascript" src="{{ url_for('static', filename='script.js') }}"></script>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet">
</head>
<body>
<h1>Welcome, {{ acct }}</h1>
<h2>You're all set up and ready to go.</h2>
<noscript>
Curious Greg will not function without JavaScript. Please ensure you have JavaScript enabled.
</noscript>
<!-- <div id='logo-main'></div> -->
<div id='body'>
You haven't posted to Curious Cat in a while, so we'll wait <em>14 minutes</em> until we check for new answers.
</div>
<div id='footer'>
Note that Curious Greg requires first-party cookies to be enabled. You may safely delete the cookie upon completing the connection process.<br />
Curious Greg will not function without JavaScript. Please ensure you have JavaScript enabled.
</div>
</body>
</html>

View file

@ -9,6 +9,9 @@
<body> <body>
<h1>Curious Greg</h1> <h1>Curious Greg</h1>
<h2>Connect your Curious Cat and Mastodon accounts for automated crossposting.</h2> <h2>Connect your Curious Cat and Mastodon accounts for automated crossposting.</h2>
<noscript>
Curious Greg will not function without JavaScript. Please ensure you have JavaScript enabled.
</noscript>
<!-- <div id='logo-main'></div> --> <!-- <div id='logo-main'></div> -->
<form onsubmit='cont(); return false'> <form onsubmit='cont(); return false'>
<label for='instance'>Instance URL</label><br /> <label for='instance'>Instance URL</label><br />
@ -16,7 +19,8 @@
<button class='loading'>Continue</button> <button class='loading'>Continue</button>
</form> </form>
<div id='footer'> <div id='footer'>
Note that Curious Greg requires first-party cookies to be enabled. You may safely delete the cookie upon completing the connection process. Note that Curious Greg requires first-party cookies to be enabled. You may safely delete the cookie upon completing the connection process.<br />
Curious Greg will not function without JavaScript. Please ensure you have JavaScript enabled.
</div> </div>
</body> </body>
</html> </html>

43
web.py
View file

@ -6,7 +6,7 @@
import requests, sqlite3, json import requests, sqlite3, json
from mastodon import Mastodon from mastodon import Mastodon
from flask import Flask, render_template from flask import Flask, render_template, request, session, redirect, url_for
cfg = json.load(open("meta.json")) cfg = json.load(open("meta.json"))
@ -17,26 +17,45 @@ c.execute("CREATE TABLE IF NOT EXISTS `data` (username VARCHAR NOT NULL, appid V
app = Flask(cfg['name']) app = Flask(cfg['name'])
app.secret_key = cfg['flask_key'] app.secret_key = cfg['flask_key']
@app.route('/') @app.route('/')
def main(): def main():
return render_template("landing_page.html") if 'acct' not in session:
return render_template("landing_page.html")
else:
return redirect(url_for('home'))
@app.route('/home')
def home():
return render_templae("home.html")
@app.route('/internal/auth_a') @app.route('/internal/auth_a')
def internal_auth_a(): def internal_auth_a():
client_id = "abc"
client_secret = "123"
instance_url = request.args.get('url', default='mastodon.social', type=str)
if not instance_url.startswith("https://"):
instance_url = "https://{}".format(instance_url)
# client_id, client_secret = Mastodon.create_app(cfg['name'], # client_id, client_secret = Mastodon.create_app(cfg['name'],
# api_base_url=instance_url, # api_base_url=instance_url,
# scopes="write:statuses", # scopes="write:statuses",
# website=cfg['website']) # website=cfg['website'])
client_id = "abc" #example URL:
client_secret = "123" #https://fedi.lynnesbian.space/oauth/authorize?scope=read:favourites&response_type=code&redirect_uri=https://t5.codesections.com&client_id=CLIENT_ID_HERE&client_secret=CLIENT_SECRET_HERE
client_info = { # client_info = {
"client_id": client_id, # "client_id": client_id,
"client_secret":client_secret, # "client_secret":client_secret,
"scopes":"write:statuses", # "scopes":"write:statuses",
"website": cfg['website'] # "website": cfg['website']
} # }
return(json.dumps(client_info)) url = "{}/oauth/authorize?scope=write:statuses&response_type=code&redirect_url=https://lynnesbian.space/cg/internal/auth_b&client_id={}&client_secret={}".format(
instance_url, client_id, client_secret
)
return url
# return(json.dumps(client_info))