Skip to content

Commit

Permalink
Merge pull request #5 from Mole1424/website
Browse files Browse the repository at this point in the history
Make into Website
  • Loading branch information
Mole1424 authored Sep 16, 2024
2 parents 9c79a3b + 864f2af commit 93bd3ea
Show file tree
Hide file tree
Showing 15 changed files with 857 additions and 383 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI # the name of our workflow is 'CI'

# run this workflow when we push to the 'main' branch
on:
push:
branches: [main]

# the list of jobs in this workflow
jobs:

# define a job
build:
name: Build and Push Container Image # the job's full name
runs-on: ubuntu-latest # the OS that this job runs on

# we need write permissions to publish the package
permissions:
packages: write

# the steps that this job consists of
steps:
- name: Checkout # check out our repo
uses: actions/checkout@v3

- name: Log in to the container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

# generate the tags that we'll use to name our image
- name: Get Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
tags: | # tag with commit hash and with 'latest'
type=sha
type=raw,value=latest,enable={{is_default_branch}}
# build and push our image, using output from previous step
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM python:3.10
RUN pip install pipenv
WORKDIR /app
COPY . .
RUN pipenv install --system
CMD gunicorn app:app -b 0.0.0.0:8080
Binary file removed Example.png
Binary file not shown.
14 changes: 14 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
flask = "*"
markdown = "*"
gunicorn = "*"

[dev-packages]

[requires]
python_version = "3.10"
167 changes: 167 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 4 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,10 @@

Because the SU generator is a pain in the ass

## Install
## Usage

1. First install python from [https://www.python.org/downloads/](https://www.python.org/downloads/) (the first link should be the correct one for your system)
2. Double click the exe file downloaded and follow the instructions on screen **MAKE SURE TO TICK `add to PATH` WHEN AVAILABLE**
3. Open a terminal by either typing `cmd` in the search bar in Windows or `command+space -> terminal` on macOS
4. Type `pythom -m pip install flask`
5. At [https://github.com/Mole1424/DofENewsletter](https://github.com/Mole1424/DofENewsletter) click on the green `Code` button and download in ZIP format
6. Unzip the file (`Right click -> extact all` on windows `double click` on mac)
How to use can be found at [https://www.youtube.com/watch?v=dQw4w9WgXcQ](https://www.youtube.com/watch?v=dQw4w9WgXcQ)

(ps if you have linux you should know how to do this)
The website uses cookies to cache input fields for security

## Run
1. Navigate to the `DofENewsletter` folder in either file explorer (windows) or finder (mac)
2. `right click -> open with terminal`
3. type `python newsletter.py`
4. Follow prompts in program
5. Events will require title, description and tl;dr (see example email)
6. Copy output in `newsletter.txt` into source page at [https://www.warwicksu.com/organisation/messages/4141/](https://www.warwicksu.com/organisation/messages/4141/)
7. Add title
8. Double check everything looks good (maybe even send as a test email just to you)
9. Send

## Edits

This was made in about half an hour so there are probably some flaws in it. The template is cloned from mailchimp and slightly edited by me to include icons and jinja scripting so sorry if its a bit cursed. To next secretary need to change name on line 1049 in `newsletter.html` from my name.

## If everything breaks

Contact me
Any other problems, contact me :)
62 changes: 62 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from flask import Flask, render_template, request
from markdown import markdown
from markdown.inlinepatterns import InlineProcessor
from markdown.extensions import Extension
from markupsafe import escape
import xml.etree.ElementTree as etree

app = Flask(__name__)


@app.route("/")
def index():
num_events = request.cookies.get("numEvents")
if num_events is None:
num_events = 1
return render_template("main.html", num_events=int(num_events))


# shamelessly stolen from docs (https://python-markdown.github.io/extensions/api/#example_3)
class DelInlineProcessor(InlineProcessor):
def handleMatch(self, m, data):
el = etree.Element("del")
el.text = m.group(1)
return el, m.start(0), m.end(0)


class DelExtension(Extension):
def extendMarkdown(self, md):
DEL_PATTERN = r"~~(.*?)~~" # like ~~del~~
md.inlinePatterns.register(DelInlineProcessor(DEL_PATTERN, md), "del", 175)


@app.route("/createEmail", methods=["POST"])
def create_email():
json = request.get_json()
week_no = json["weekNo"]
introduction = json["introduction"]
events = json["events"]
for event in events:
event["description"] = markdown(
escape(event["description"]), extensions=[DelExtension()]
)
conclusion = json["conclusion"]
name = json["name"]
whatsapp = json["whatsapp"]
instagram = json["instagram"]
email = json["email"]
facebook = json["facebook"]
website = json["website"]
return render_template(
"newsletter.html",
week_no=week_no,
introduction=introduction,
events=events,
conclusion=conclusion,
name=name,
whatsapp=whatsapp,
instagram=instagram,
email=email,
facebook=facebook,
website=website,
)
Loading

0 comments on commit 93bd3ea

Please sign in to comment.