diff --git a/app/controllers/euler_problem_texts.py b/app/controllers/euler_problem_texts.py new file mode 100755 index 0000000..af4345b --- /dev/null +++ b/app/controllers/euler_problem_texts.py @@ -0,0 +1,20 @@ +import requests, json +from bs4 import BeautifulSoup + +URL = "https://projecteuler.net/problem={}" + +def getBS(url): + r = requests.get(url) + data = r.text + return BeautifulSoup(data,"lxml") + +problems = {} +for i in range(1, 701): + print(i) + problem = getBS(URL.format(i)) + problem_tag = problem.find("div", {"class":"problem_content"}) + problem_title = problem.find("h2").text + problem_html = str(problem_tag).replace("project/images/", "https://projecteuler.net/project/images/") + problems[i] = {"title":problem_title, "problem":problem_html} + +open("problems.json", "w"). write(json.dumps(problems, ensure_ascii=False, indent=4)) \ No newline at end of file diff --git a/app/controllers/translations_controller.rb b/app/controllers/translations_controller.rb index 63495e9..e6702db 100644 --- a/app/controllers/translations_controller.rb +++ b/app/controllers/translations_controller.rb @@ -1,9 +1,15 @@ +require "json" + class TranslationsController < ApplicationController before_action :set_problem, only: [:new, :create] before_action :set_accept, only: [:create] # GET /translations/new def new + file = File.open "app/controllers/problems.json" + problem_json = JSON.load file + @original_title = problem_json[@problem.id.to_s]["title"] + @original_problem = problem_json[@problem.id.to_s]["problem"] @translation = @problem.translations.build if @problem.is_translated? @translation.title = @problem.translation.title diff --git a/app/views/translations/_translation-tips.de.html.erb b/app/views/translations/_translation-tips.de.html.erb index e0bb687..d02d798 100644 --- a/app/views/translations/_translation-tips.de.html.erb +++ b/app/views/translations/_translation-tips.de.html.erb @@ -4,15 +4,19 @@
+ +
+
+ Originaler Text der Aufgabe "<%= @original_title %>" +
+
+ <%= raw(@original_problem) %> +
\ No newline at end of file