mirror of
https://github.com/Findus23/se-simulator.git
synced 2024-09-19 15:53:45 +02:00
Merge branch 'master' of github.com:Findus23/se-simulator
This commit is contained in:
commit
d6cee9fc13
7 changed files with 84 additions and 13 deletions
|
@ -36,8 +36,8 @@ class User(BaseModel):
|
|||
|
||||
class Question(BaseModel):
|
||||
text = TextField()
|
||||
upvotes = IntegerField(default=0)
|
||||
downvotes = IntegerField(default=0)
|
||||
upvotes = IntegerField(default=1)
|
||||
downvotes = IntegerField(default=1)
|
||||
title = ForeignKeyField(Title)
|
||||
user = ForeignKeyField(User)
|
||||
site = ForeignKeyField(Site)
|
||||
|
@ -47,8 +47,8 @@ class Question(BaseModel):
|
|||
|
||||
class Answer(BaseModel):
|
||||
text = TextField()
|
||||
upvotes = IntegerField(default=0)
|
||||
downvotes = IntegerField(default=0)
|
||||
upvotes = IntegerField(default=1)
|
||||
downvotes = IntegerField(default=1)
|
||||
datetime = DateTimeField()
|
||||
question = ForeignKeyField(Question, null=True)
|
||||
user = ForeignKeyField(User)
|
||||
|
|
40
server.py
40
server.py
|
@ -1,10 +1,12 @@
|
|||
import subprocess
|
||||
import time
|
||||
from io import BytesIO
|
||||
from random import shuffle, randint
|
||||
|
||||
import sass
|
||||
from PIL import ImageFont, Image, ImageDraw
|
||||
from flask import render_template, send_from_directory, abort, session, jsonify, make_response, redirect, url_for, \
|
||||
request
|
||||
request, send_file
|
||||
from flask_limiter import Limiter
|
||||
from flask_limiter.util import get_remote_address
|
||||
from flask_session import Session
|
||||
|
@ -157,9 +159,39 @@ def sites():
|
|||
return jsonify(data)
|
||||
|
||||
|
||||
@app.route('/test')
|
||||
def sdfdsfds():
|
||||
return ""
|
||||
@app.route('/image')
|
||||
@app.route('/image/<int:site_id>')
|
||||
@limiter.limit("10 per minute")
|
||||
def image(site_id=None):
|
||||
if site_id:
|
||||
query = Site.select().where((Site.last_download.is_null(False)) & (Site.id == site_id))
|
||||
site = get_object_or_404(query)
|
||||
else:
|
||||
class DummySite(object):
|
||||
pass
|
||||
|
||||
site = DummySite()
|
||||
site.foreground_color = 'black'
|
||||
site.background_color = 'white'
|
||||
# parameters
|
||||
text = "Stack Exchange\nSimulator"
|
||||
selected_font = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
|
||||
font_size = 70
|
||||
W, H = (600, 600)
|
||||
# # get the size of the text
|
||||
img = Image.new('RGBA', (W, H), (site.background_color if site.background_color else "white"))
|
||||
font = ImageFont.truetype(selected_font, font_size)
|
||||
draw = ImageDraw.Draw(img)
|
||||
w, h = draw.multiline_textsize(text, font)
|
||||
|
||||
draw.multiline_text(((W - w) / 2, (H - h) / 2), text,
|
||||
font=font, align="center",
|
||||
fill=(site.foreground_color if site.foreground_color else "black"))
|
||||
|
||||
byte_io = BytesIO()
|
||||
img.save(byte_io, 'PNG', optimize=True)
|
||||
byte_io.seek(0)
|
||||
return send_file(byte_io, mimetype='image/png')
|
||||
|
||||
|
||||
@app.route('/api/vote/<string:type>/<int:id>/<string:vote>', methods=["POST"])
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="de" class="{% block extraclasses %}{% endblock %}">
|
||||
<html lang="de" class="{% block extraclasses %}{% endblock %}" prefix="og: http://ogp.me/ns#">
|
||||
<head>
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>{% block title %}Stackexchange Simulator{% endblock %}</title>
|
||||
<title>{% block title %}Stack Exchange Simulator{% endblock %}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
{% if config['DEBUG'] %}
|
||||
<link href="{{ url_for('static', filename='css/style.scss.css') }}" rel="stylesheet" type="text/css">
|
||||
|
@ -10,6 +10,15 @@
|
|||
<link href="{{ url_for('static', filename='css/style.css') }}?hash={{ git_hash }}"
|
||||
rel="stylesheet" type="text/css">
|
||||
{% endif %}
|
||||
<meta property="og:type" content="website"/>
|
||||
<meta property="og:site_name" content="Stack Exchange Simulator"/>
|
||||
<meta property="og:image:width" content="600"/>
|
||||
<meta property="og:image:height" content="600"/>
|
||||
<meta name="twitter:card" content="summary"/>
|
||||
<meta name="twitter:site" content="@lw1_at"/>
|
||||
<meta name="twitter:creator" content="@lw1_at"/>
|
||||
<meta property="og:url" content="{{ request.base_url }}"/>
|
||||
{% block extrameta %}{% endblock %}
|
||||
<!-- Matomo -->
|
||||
<script type="text/javascript">
|
||||
var _paq = _paq || [];
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
{% extends "base.html" %}
|
||||
{% from 'macros.html' import siteheader %}
|
||||
{% block title %}
|
||||
{{ question.title.text }} - Stackexchange Simulator
|
||||
{{ question.title.text }} - Stack Exchange Simulator
|
||||
{% endblock %}
|
||||
{% block extrameta %}
|
||||
<meta property="og:image" name="twitter:image" itemprop="image primaryImageOfPage"
|
||||
content="{{ url_for("image",site_id=question.site.id,_external=True) }}"/>
|
||||
<meta name="twitter:domain" content="se-simulator.lw1.at"/>
|
||||
<meta name="twitter:title" property="og:title" itemprop="title name" content="{{ question.title.text }}"/>
|
||||
<meta name="twitter:description" property="og:description" itemprop="description"
|
||||
content="{{ question.text|truncate(200, False, ' …', 10) }}">
|
||||
|
||||
<meta name="theme-color" content="{{ question.site.background_color }}">
|
||||
{% endblock %}
|
||||
{% block body %}
|
||||
{{ siteheader(question.site) }}
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
{% extends "base.html" %}
|
||||
{% from 'macros.html' import pagination, siteheader %}
|
||||
{% block extrameta %}
|
||||
<meta property="og:image" name="twitter:image" itemprop="image primaryImageOfPage"
|
||||
content="{{ url_for("image",site_id=site.id,_external=True) }}"/>
|
||||
<meta name="twitter:domain" content="se-simulator.lw1.at"/>
|
||||
<meta name="twitter:title" property="og:title" itemprop="title name" content="Stack Exchange Simulator"/>
|
||||
<meta name="twitter:description" property="og:description" itemprop="description"
|
||||
content="Generating fun Stack Overflow and Stack Exchange Questions using Markov Chains">
|
||||
{% if site.background_color %}
|
||||
<meta name="theme-color" content="{{ site.background_color }}">
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block body %}
|
||||
{{ siteheader(site) }}
|
||||
|
||||
|
|
|
@ -1,12 +1,20 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}
|
||||
Stackexchange Simulator Quiz - {{ question.title.text }}
|
||||
Stack Exchange Simulator Quiz - {{ question.title.text }}
|
||||
{% endblock %}
|
||||
{% block extrameta %}
|
||||
<meta property="og:image" name="twitter:image" itemprop="image primaryImageOfPage"
|
||||
content="{{ url_for("image",_external=True) }}"/>
|
||||
<meta name="twitter:domain" content="se-simulator.lw1.at"/>
|
||||
<meta name="twitter:title" property="og:title" itemprop="title name" content="Stack Exchange Simulator Quiz"/>
|
||||
<meta name="twitter:description" property="og:description" itemprop="description"
|
||||
content="Generating fun Stack Overflow and Stack Exchange Questions using Markov Chains">
|
||||
{% endblock %}
|
||||
{% block extraclasses %}quiz{% endblock %}
|
||||
{% block body %}
|
||||
|
||||
<header>
|
||||
<h1>Stackexchange Simulator Quiz</h1>
|
||||
<h1>Stack Exchange Simulator Quiz</h1>
|
||||
</header>
|
||||
|
||||
{% if stats.correct <3 %}
|
||||
|
|
1
utils.py
1
utils.py
|
@ -111,6 +111,7 @@ AS ci_lower_bound
|
|||
|
||||
def get_fallback_site():
|
||||
return {
|
||||
"id": None,
|
||||
"name": "Stack Exchange",
|
||||
"url": "stackexchange.com/",
|
||||
"icon_url": "https://cdn.sstatic.net/Sites/stackexchange/img/apple-touch-icon.png",
|
||||
|
|
Loading…
Reference in a new issue