Skip to content

Commit

Permalink
Merge pull request #1 from metaodi/diff-stuff
Browse files Browse the repository at this point in the history
Diff stuff
  • Loading branch information
metaodi committed Mar 15, 2024
2 parents 73e6574 + 3cb1c2c commit 6e46d60
Show file tree
Hide file tree
Showing 9 changed files with 2,207 additions and 1,018 deletions.
56 changes: 34 additions & 22 deletions app.py
Expand Up @@ -3,6 +3,7 @@
from flask import Flask, jsonify, request, render_template
from flask_cors import CORS
from github import Github
import uuid

from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv())
Expand All @@ -25,34 +26,41 @@
def home():
args = request.args

con_id = args.get("consultation_id")
sr_id = args.get("sr_id")

# read json
content = {}
if con_id:
json_path = os.path.join("fedlex", f"{con_id}.json")
content = {'_metadata': {}, 'lines': {}}
if sr_id:
json_path = os.path.join("fedlex", f"{sr_id}.json")
with open(json_path) as f:
content = json.loads(f.read())

return render_template('index.html', consultation_id=con_id, content=content)
return render_template('index.html', sr_id=sr_id, content=content['lines'], **content['_metadata'])

@app.route('/submit_consultation', methods=['POST'])
def submit_calendar():
response = {"status": "success"}
data = request.get_json()
print(data)
def submit_consultation():
sr_id = request.form['sr_id']

# filename = data['municipality'].replace(' ', '_').replace('.', '').lower()
# repo_path = f"csv/{filename}.csv"
# read json
json_path = os.path.join("fedlex", f"{sr_id}.json")
with open(json_path) as f:
content = json.loads(f.read())

keys = request.form.getlist('keys')
for key in keys:
content['lines'][key]['text'] = request.form[f"{key}_text"]
content['lines'][key]['comment'] = request.form[f"{key}_comment"]
content_text = json.dumps(content, indent=4)

# br_id = str(uuid.uuid4())
# branch = f"{filename}-{br_id}"
repo_path = f"fedlex/{sr_id}.json"
br_id = str(uuid.uuid4())
branch = f"{sr_id}-{br_id}"
create_branch(branch)
update_file_in_branch(branch, content_text, repo_path)

# create_branch(branch)
# add_csv_to_branch(branch, fp, repo_path)
# create_pull_request(branch, f"New data for {data['municipality']}", "Please check")
pr_url = create_pull_request(branch, f"New consultation for {content['_metadata']['short']}", "Please add your comments")

return jsonify(response)
return render_template('consultation.html', pr_url=pr_url, content=content)


# function to create new branch (wiring to app still missing)
Expand Down Expand Up @@ -81,7 +89,7 @@ def create_branch(new_branch_name):


# function to add file to branch
def add_csv_to_branch(branch_name, csv_file, repo_path):
def update_file_in_branch(branch_name, content, repo_path):
# Replace with the name of your repository and the owner's username
REPO_NAME = 'govtech24_kommentator2000'
OWNER_NAME = 'metaodi'
Expand All @@ -95,20 +103,23 @@ def add_csv_to_branch(branch_name, csv_file, repo_path):
# Get the branch object
branch = repo.get_branch(branch_name)

# get current file
contents = repo.get_contents(repo_path)

# Read the contents of the CSV file
contents = csv_file.read()
print(contents)

# Create the new file in the repository
repo.create_file(
repo.update_file(
path=repo_path,
message='Add consultation version',
content=contents,
sha=contents.sha,
content=content,
branch=branch_name
)

# Print a success message
print('File added to branch.')
print('File updated in branch.')

# function to create pull request
def create_pull_request(branch_name, title, description):
Expand All @@ -135,6 +146,7 @@ def create_pull_request(branch_name, title, description):

# Print a success message with the pull request URL
print(f"Pull request created successfully: {pull_request.html_url}")
return pull_request.html_url

if __name__ == '__main__':
app.run()
Expand Down
2,490 changes: 1,567 additions & 923 deletions fedlex/172.010.1.json

Large diffs are not rendered by default.

376 changes: 376 additions & 0 deletions fedlex/412.101.221.85.json

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions fedlex/901.021.json
@@ -0,0 +1,88 @@
{
"_metadata": {
"title": "Verordnung vom 28. November 2007 \u00fcber Regionalpolitik (VRP)",
"short": "VRP",
"frbr_nr": "901.021",
"uri": "https://fedlex.data.admin.ch/eli/cc/2007/885/20240401"
},
"lines": {
"https://fedlex.data.admin.ch/eli/cc/2007/885/20240401/art_1/para_1": {
"article_num": "Art. 1",
"par_num": "1",
"text": "",
"comment": ""
},
"https://fedlex.data.admin.ch/eli/cc/2007/885/20240401/art_1/para_2": {
"article_num": "Art. 1",
"par_num": "2",
"text": "",
"comment": ""
},
"https://fedlex.data.admin.ch/eli/cc/2007/885/20240401/art_1/para_3": {
"article_num": "Art. 1",
"par_num": "3",
"text": "Im Rahmen der Programmvereinbarungen kann das SECO auch einzelne Gemeinden in den \u00f6rtlichen Wirkungsbereich aufnehmen, wenn dies im Zusammenhang mit einem konkreten Projekt zweckm\u00e4ssig erscheint. Die Aufnahme gilt nur bis zum Abschluss des betreffenden Projektes.",
"comment": ""
},
"https://fedlex.data.admin.ch/eli/cc/2007/885/20240401/art_1/para_4": {
"article_num": "Art. 1",
"par_num": "4",
"text": "Die Antr\u00e4ge auf Erweiterung des \u00f6rtlichen Wirkungsbereichs sind jeweils zusammen mit dem Umsetzungsprogramm einzureichen.",
"comment": ""
},
"https://fedlex.data.admin.ch/eli/cc/2007/885/20240401/art_2/para": {
"article_num": "Art. 2",
"par_num": "",
"text": "Auf Antrag der Kantone und Regionen werden vom SECO Ad-hoc-Konferenzen einberufen. Diese stellen die Zusammenarbeit mit den Kantonen, den Gemeinden, dem Berggebiet und dem weiteren l\u00e4ndlichen Raum sicher.",
"comment": ""
},
"https://fedlex.data.admin.ch/eli/cc/2007/885/20240401/art_2_a/para_1": {
"article_num": "Art. 2",
"par_num": "1",
"text": "",
"comment": ""
},
"https://fedlex.data.admin.ch/eli/cc/2007/885/20240401/art_2_a/para_2": {
"article_num": "Art. 2",
"par_num": "2",
"text": "Der H\u00f6chstbetrag f\u00fcr die F\u00f6rderung von Infrastrukturvorhaben mit A-Fonds-perdu-Beitr\u00e4gen betr\u00e4gt unter Ber\u00fccksichtigung der Teuerung 50\u00a0000\u00a0Franken. Dazu kommen \u00e4quivalente Mittel der Kantone sowie angemessene Eigenmittel des Projekttr\u00e4gers. Das Gesamtbudget eines solchen Vorhabens betr\u00e4gt h\u00f6chstens 700\u00a0000\u00a0Franken.",
"comment": ""
},
"https://fedlex.data.admin.ch/eli/cc/2007/885/20240401/art_3/para_1": {
"article_num": "Art. 3",
"par_num": "1",
"text": "Die Kantone reichen dem SECO jeweils auf Anfang eines neuen Kalenderjahres einen Jahresabschluss sowie eine \u00dcbersicht \u00fcber den Stand der von ihnen verwalteten Finanzhilfe- und Darlehensgesch\u00e4fte ein.",
"comment": ""
},
"https://fedlex.data.admin.ch/eli/cc/2007/885/20240401/art_3/para_2": {
"article_num": "Art. 3",
"par_num": "2",
"text": "Die aus den Darlehensgesch\u00e4ften w\u00e4hrend eines Jahres eingegangenen Amortisationen, Zinszahlungen und Garantieleistungen Dritter sowie die von den Kantonen in dieser Zeit zu erbringenden Haftungsleistungen nach Artikel 8 Absatz 3 des Bundesgesetzes vom 6. Oktober 2006 \u00fcber Regionalpolitik sind j\u00e4hrlich an den Fonds f\u00fcr Regionalentwicklung des Bundes zu \u00fcberweisen.",
"comment": ""
},
"https://fedlex.data.admin.ch/eli/cc/2007/885/20240401/art_4/para_1": {
"article_num": "Art. 4",
"par_num": "1",
"text": "Die Finanzaufsicht wird von der Eidgen\u00f6ssischen Finanzkontrolle und den kantonalen Finanzkontrollen gemeinsam sichergestellt.",
"comment": ""
},
"https://fedlex.data.admin.ch/eli/cc/2007/885/20240401/art_4/para_2": {
"article_num": "Art. 4",
"par_num": "2",
"text": "Die Einzelheiten der Finanzaufsicht werden im Einvernehmen mit der Eidgen\u00f6ssischen Finanzkontrolle und den kantonalen Finanzkontrollen in den Programmvereinbarungen mit den Kantonen geregelt.",
"comment": ""
},
"https://fedlex.data.admin.ch/eli/cc/2007/885/20240401/art_5/para": {
"article_num": "Art. 5",
"par_num": "",
"text": "Die Verordnung vom 26. November 1997",
"comment": ""
},
"https://fedlex.data.admin.ch/eli/cc/2007/885/20240401/art_6/para": {
"article_num": "Art. 6",
"par_num": "",
"text": "Diese Verordnung tritt am 1. Januar 2008 in Kraft.",
"comment": ""
}
}
}
2 changes: 2 additions & 0 deletions requirements.txt
Expand Up @@ -4,3 +4,5 @@ Flask
Flask-Cors
python-dotenv
pygithub
requests
SPARQLWrapper==1.8.2
9 changes: 9 additions & 0 deletions templates/consultation.html
@@ -0,0 +1,9 @@
{% extends 'base.html' %}

{% block content %}
<h1>{% block title %} Vernehmlassung erstellt {% endblock %}</h1>
<p>Strukturierte Vernehmlassung erfolgreich erstellt.</p>
<p><a href="{{ pr_url }}">Änderungen auf GitHub ansehen</a></p>
<pre>{{ content if content}}</pre>
{% endblock %}

25 changes: 18 additions & 7 deletions templates/index.html
Expand Up @@ -4,24 +4,35 @@
<h1>{% block title %} Vernehmlassung 2000 {% endblock %}</h1>
<form method="get">
<div class="form-group">
<label for="consultation_id" value="{{ request.args['consultation_id'] }}">Fedlex Nummer der Vernehmlassung</label>
<input type="text" class="form-control" name="consultation_id" aria-describedby="fedlexlHelp" value="{{ consultation_id }}" placeholder="172.010.1">
<label for="sr_id" value="{{ request.args['consultation_id'] }}">SR-Nummer des Gesetzestexts</label>
<input type="text" class="form-control" name="sr_id" aria-describedby="fedlexlHelp" value="{{ sr_id if sr_id}}" placeholder="172.010.1">
<small id="fedlexHelp" class="form-text text-muted">SR-Nummer für die eine Vernehmlassung gestartet werden sll (z.B. 172.010.1).</small>
</div>
<button type="submit" class="btn btn-primary">Gesetzestext laden</button>
</form>
<form>
<form action="{{ url_for('submit_consultation')}}" method="post">
<input type="hidden" name="sr_id" value="{{ sr_id if sr_id}}" />
<hr>
{% set ns = namespace(article='') %}
<h2>{{ title }}</h2>
{% for key in content %}
<input id="{{key}}_key" name="keys" type="hidden" value="{{key}}" />
<div class="form-group">
<label for="exampleFormControlTextarea1">Example textarea</label>
<textarea class="form-control" id="{{key}}_text" name="{{key}}_text" rows="3">
{{ content[key]['text'] }}
</textarea>
{% if ns.article != content[key]['article_num'] %}
{% set ns.article = content[key]['article_num'] %}
<label for="{{key}}_text"><strong>{{ ns.article }}</strong></label>
{% elif content[key]['par_num'] != "" %}
<label for="{{key}}_text">Par. {{ content[key]['par_num'] }}</label>
{% else %}
<label for="{{key}}_text">{{ key }}</label>
{% endif %}
<textarea class="form-control" id="{{key}}_text" name="{{key}}_text" rows="3">{{ content[key]['text'] }}</textarea>
</div>
<div class="form-group">
<input class="form-control form-control-lg" id="{{key}}_comment" name="{{key}}_comment"type="text" placeholder="Kommentar">
</div>
{% endfor %}
<button type="submit" class="btn btn-primary">Vernehmlassung erstellen</button>
</form>


Expand Down
66 changes: 0 additions & 66 deletions xml_parse.py

This file was deleted.

0 comments on commit 6e46d60

Please sign in to comment.