source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/api/oparl/current.rb
Ruby
mit
45
master
1,652
# # current_url and current_path-helpers for grape / grape-route-helpers # module OParl module Current def self.included(base) base.class_eval do helpers do def current_path(*options) options[0] = prepare_params(options[0]) OParl::Routes.method_missing(current_helpe...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/api/oparl/entities/text_file.rb
Ruby
mit
45
master
1,754
module OParl module Entities # file is currently a paper too, until we support multiple files per paper. class TextFile < Grape::Entity expose(:id) { |paper| OParl::Routes.oparl_v1_body_term_paper_file_url(body: paper.body.key, term: paper.legislative_term, paper: paper.reference, file: 2) } expos...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/api/oparl/entities/person.rb
Ruby
mit
45
master
823
module OParl module Entities class Person < Grape::Entity expose(:id) { |person| OParl::Routes.oparl_v1_person_url(person: person.slug) } expose(:type) { |_| 'https://schema.oparl.org/1.0/Person' } expose(:body) { |person| OParl::Routes.oparl_v1_body_url(body: person.latest_body.key) } w...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/api/oparl/entities/file.rb
Ruby
mit
45
master
1,764
module OParl module Entities # file is currently a paper too, until we support multiple files per paper. class File < Grape::Entity expose(:id) { |paper| OParl::Routes.oparl_v1_body_term_paper_file_url(body: paper.body.key, term: paper.legislative_term, paper: paper.reference, file: 1) } expose(:t...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/api/oparl/entities/legislative_term.rb
Ruby
mit
45
master
970
module OParl module Entities class LegislativeTerm < Grape::Entity expose(:id) { |lt| OParl::Routes.oparl_v1_body_term_url(body: lt.body.key, term: lt.term) } expose(:type) { |_| 'https://schema.oparl.org/1.0/LegislativeTerm' } expose(:body, if: { type: :lt_full }) { |lt| OParl::Routes.oparl_v1_...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/api/oparl/entities/system.rb
Ruby
mit
45
master
867
module OParl module Entities class System < Grape::Entity expose(:id) { |_| OParl::Routes.oparl_v1_system_url } expose(:type) { |_| 'https://schema.oparl.org/1.0/System' } expose(:oparlVersion) { |_| 'https://schema.oparl.org/1.0/' } expose(:license) { |_| 'http://opendatacommons.org/licen...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/api/oparl/entities/paper.rb
Ruby
mit
45
master
2,037
module OParl module Entities class Paper < Grape::Entity expose(:id) { |paper| OParl::Routes.oparl_v1_body_term_paper_url(body: paper.body.key, term: paper.legislative_term, paper: paper.reference) } expose(:type) { |_| 'https://schema.oparl.org/1.0/Paper' } expose(:body) { |paper| OParl::Route...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/api/oparl/entities/body.rb
Ruby
mit
45
master
1,275
module OParl module Entities class Body < Grape::Entity expose(:id) { |body| OParl::Routes.oparl_v1_body_url(body: body.key) } expose(:type) { |_| 'https://schema.oparl.org/1.0/Body' } expose(:system) { |_| OParl::Routes.oparl_v1_system_url } expose(:shortName) { |body| body.state } ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/api/oparl/entities/organization.rb
Ruby
mit
45
master
1,092
module OParl module Entities class Organization < Grape::Entity expose(:id) { |org, options| OParl::Routes.oparl_v1_body_organization_url(body: options[:body].key, organization: org.slug) } expose(:type) { |_| 'https://schema.oparl.org/1.0/Organization' } expose(:body) { |org, options| OParl::R...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/models/organization.rb
Ruby
mit
45
master
418
class Organization < ApplicationRecord extend FriendlyId acts_as_paranoid include NkSyncable has_and_belongs_to_many :members, class_name: 'Person' friendly_id :name, use: :slugged has_many :paper_originators, as: :originator, dependent: :destroy has_many :papers, -> { answers }, through: :paper_origin...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/models/body.rb
Ruby
mit
45
master
1,842
class Body < ApplicationRecord extend FriendlyId friendly_id :name, use: :slugged has_many :papers, -> { answers } has_many :ministries has_many :organizations, -> { distinct }, through: :papers, source: :originator_organizations has_many :scraper_results has_many :legislative_terms, -> { order(term: :des...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/models/paper_originator.rb
Ruby
mit
45
master
272
class PaperOriginator < ApplicationRecord belongs_to :paper belongs_to :originator, polymorphic: true validates :originator_id, uniqueness: { scope: [:paper_id, :originator_type] }, unless: Proc.new { |o| o.paper_id.blank? || o.originator_type.blank? } end
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/models/legislative_term.rb
Ruby
mit
45
master
232
class LegislativeTerm < ApplicationRecord belongs_to :body validates :term, uniqueness: { scope: [:body_id] } has_many :papers, -> (lt) { where(legislative_term: lt.term) }, through: :body def to_param term end end
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/models/paper.rb
Ruby
mit
45
master
11,319
class Paper < ApplicationRecord extend FriendlyId friendly_id :reference_and_title, use: :scoped, scope: [:body, :legislative_term] acts_as_paranoid DOCTYPE_MINOR_INTERPELLATION = 'minor'.freeze DOCTYPE_MAJOR_INTERPELLATION = 'major'.freeze DOCTYPE_WRITTEN_INTERPELLATION = 'written'.freeze DOCTYPES = [ ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/models/search_terms.rb
Ruby
mit
45
master
3,237
# Search term parser from https://gist.github.com/1477730 # Modified to allow periods, other non-letter chars and >=/<= in unquoted field values # and field names. # # Helper class to help parse out more advanced search terms # from a form query # # Note: all hash keys are downcased, so ID:10 == {'id' => 10} # yo...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/models/paper_redirect.rb
Ruby
mit
45
master
257
class PaperRedirect < ApplicationRecord belongs_to :body belongs_to :paper validates :body, presence: true validates :legislative_term, presence: true validates :reference, presence: true, uniqueness: { scope: [:body_id, :legislative_term] } end
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/models/ministry.rb
Ruby
mit
45
master
349
class Ministry < ApplicationRecord extend FriendlyId acts_as_paranoid include NkSyncable belongs_to :body friendly_id :name, use: :scoped, scope: :body has_many :paper_answerers, as: :answerer, dependent: :destroy has_many :papers, -> { answers }, through: :paper_answerers validates :name, uniquenes...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/models/paper_relation.rb
Ruby
mit
45
master
553
class PaperRelation < ApplicationRecord REASON_REFERENCE_IN_TITLE = 'reference_in_title' REASON_REFERENCE_IN_TEXT = 'reference_in_text' belongs_to :paper belongs_to :other_paper, class_name: 'Paper' validates :paper, :other_paper, :reason, presence: true validates :other_paper, uniqueness: { scope: [:pape...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/models/scraper_result.rb
Ruby
mit
45
master
874
class ScraperResult < ApplicationRecord belongs_to :body def status if queued? 'waiting' elsif success? 'success' elsif running? 'running' else 'failure' end end def queued? !created_at.nil? && started_at.nil? && stopped_at.nil? end def running? !starte...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/models/person.rb
Ruby
mit
45
master
509
class Person < ApplicationRecord extend FriendlyId acts_as_paranoid include NkSyncable friendly_id :name, use: :slugged has_and_belongs_to_many :organizations has_many :paper_originators, as: :originator, dependent: :destroy has_many :papers, -> { answers }, through: :paper_originators validates :na...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/models/concerns/nk_syncable.rb
Ruby
mit
45
master
1,584
module NkSyncable extend ActiveSupport::Concern def nomenklatura_dataset if has_attribute?(:body) || has_attribute?(:body_id) state = body.state elsif self.class.method_defined? :bodies fail 'This entity appears in multiple bodies' if bodies.size > 1 state = bodies.first.state else ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/views/paper/_paper.atom.builder
Ruby
mit
45
master
822
url = paper_url(body: paper.body, legislative_term: paper.legislative_term, paper: paper) feed.entry paper, published: paper.published_at, updated: paper.updated_at, url: url do |entry| title = paper.title if params[:feedformat] == 'twitter' title += " (#{paper.originators.map(&:name).join(', ')})" if title.si...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/views/paper/recent.atom.builder
Ruby
mit
45
master
630
atom_feed(language: 'de-DE', root_url: recent_url) do |feed| down_date = Date.new(2020, 12, 31) url = Rails.application.routes.url_helpers.obituary_url feed.title "kleineAnfragen: Anfragen der letzten Tage" feed.updated down_date feed.author { |author| author.name 'kleineAnfragen' } feed.entry Paper.new,...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/views/body/feed.atom.builder
Ruby
mit
45
master
1,028
atom_feed( language: 'de-DE', root_url: body_feed_url(body: @body), url: feed_url_with_current_page(@papers) ) do |feed| paginated_feed(feed, @papers) down_date = Date.new(2020, 12, 31) url = Rails.application.routes.url_helpers.obituary_url if !Rails.configuration.x.push_hubs.blank? Rails.configur...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/views/search/search.atom.builder
Ruby
mit
45
master
773
atom_feed( language: 'de-DE', root_url: search_url(q: @query), url: feed_url_with_current_page(@papers, q: @query), id: search_feed_id(@query, params[:page]), 'xmlns:opensearch' => 'http://a9.com/-/spec/opensearch/1.1/' ) do |feed| paginated_feed(feed, @papers, q: @query) feed.title "kleineAnfragen: Suche...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/views/search/_searchresult.atom.builder
Ruby
mit
45
master
922
url = paper_url(body: paper.body, legislative_term: paper.legislative_term, paper: paper) feed.entry paper, published: paper.published_at, updated: paper.updated_at, url: url do |entry| # items like in html search result title = paper.search_highlights.try(:fetch, :title, nil).try(:html_safe) || paper.title if ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/views/search/opensearch.xml.builder
Ruby
mit
45
master
584
xml.instruct! xml.OpenSearchDescription(:xmlns => 'http://a9.com/-/spec/opensearch/1.1/', 'xmlns:moz' => 'http://www.mozilla.org/2006/browser/search/') do xml.ShortName('kleineAnfragen') xml.Description('kleineAnfragen Suche') xml.InputEncoding('UTF-8') xml.Image(root_url.chomp('/') + '/favicon.ico', height: 16...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/views/ministry/show.atom.builder
Ruby
mit
45
master
477
atom_feed( language: 'de-DE', root_url: ministry_url(body: @body, ministry: @ministry), url: feed_url_with_current_page(@papers) ) do |feed| paginated_feed(feed, @papers) feed.title "kleineAnfragen: Anfragen beantwortet von #{@ministry.name}, #{@body.name}" feed.updated @papers.maximum(:updated_at) feed.a...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/views/organization/show.atom.builder
Ruby
mit
45
master
490
atom_feed( language: 'de-DE', root_url: organization_url(body: @body, organization: @organization), url: feed_url_with_current_page(@papers) ) do |feed| paginated_feed(feed, @papers) feed.title "kleineAnfragen: Anfragen gestellt von #{@organization.name}, #{@body.name}" feed.updated @papers.maximum(:updated...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/extract_originators_job.rb
Ruby
mit
45
master
1,207
class ExtractOriginatorsJob < PaperJob queue_as :meta EXTRACTORS = { 'BT' => BundestagPDFExtractor, 'BW' => BadenWuerttembergPDFExtractor, 'BY' => BayernPDFExtractor, 'HB' => BremenPDFExtractor, 'MV' => MeckPommPDFExtractor, 'NW' => NordrheinWestfalenPDFExtractor, 'RP' => RheinlandPfalz...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/extract_answerers_job.rb
Ruby
mit
45
master
1,037
class ExtractAnswerersJob < PaperJob queue_as :meta EXTRACTORS = { 'BB' => BrandenburgPDFExtractor, 'BE' => BerlinPDFExtractor, 'BY' => BayernPDFExtractor, 'HE' => HessenPDFExtractor, 'MV' => MeckPommPDFExtractor, 'SN' => SachsenPDFExtractor, 'SH' => SchleswigHolsteinPDFExtractor, '...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/determine_paper_type_job.rb
Ruby
mit
45
master
698
class DeterminePaperTypeJob < PaperJob queue_as :meta EXTRACTORS = { 'MV' => MvPDFHasAnswerExtractor, 'HH' => HamburgPDFHasAnswerExtractor, 'HE' => HessenPDFExtractor, 'SL' => SaarlandPDFExtractor } def perform(paper) return unless EXTRACTORS.keys.include?(paper.body.state) fail "No Te...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/reimport_missing_pdf_job.rb
Ruby
mit
45
master
328
class ReimportMissingPDFJob < ApplicationJob queue_as :meta def perform Paper.where(downloaded_at: nil).where.not(url: nil).find_each do |paper| logger.info "Adding reimport of Paper [#{paper.body.state} #{paper.full_reference}] to queue" StorePaperPDFJob.perform_later(paper, force: true) end ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/load_paper_details_job.rb
Ruby
mit
45
master
1,124
class LoadPaperDetailsJob < PaperJob queue_as :meta OVERWRITEABLE = [:originators, :answerers, :doctype, :url] def perform(paper) return unless paper.body.scraper.const_defined? :Detail logger.info "Loading details for Paper [#{paper.body.state} #{paper.full_reference}]" scraper = paper.body.scrape...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/import_paper_job.rb
Ruby
mit
45
master
1,869
class ImportPaperJob < ApplicationJob queue_as :import def perform(body, legislative_term, reference) fail "No scraper found for body #{body.state}" if body.scraper.nil? scraper = body.scraper::Detail.new(legislative_term, reference) logger.progname = "ImportPaperJob #{body.state}" scraper.logger =...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/fill_paper_pdf_last_modified_job.rb
Ruby
mit
45
master
1,308
class FillPaperPDFLastModifiedJob < PaperJob queue_as :meta # Paper.where(pdf_last_modified: nil).each {|p| FillPaperPDFLastModifiedJob.perform_later(p) } def perform(paper) session = patron_session url = paper.url resp = nil loop do resp = session.head(url) if resp.status > 300 && r...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/count_page_numbers_job.rb
Ruby
mit
45
master
459
class CountPageNumbersJob < PaperJob queue_as :meta def perform(paper) logger.info "Counting Pages of the Paper [#{paper.body.state} #{paper.full_reference}]" # FIXME: not multi host capable unless File.exist? paper.local_path fail "No local copy of the PDF of Paper [#{paper.body.state} #{paper....
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/paper_job.rb
Ruby
mit
45
master
374
class PaperJob < ApplicationJob # before_perform with a symbol doesn't get job as argument, so wrap it here before_perform ->(job) { skip_if_frozen(job) } def skip_if_frozen(job) paper = job.arguments.first if paper.frozen? logger.info "Skipping because Paper [#{paper.body.state} #{paper.full_refer...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/notify_push_hub_body_feed_job.rb
Ruby
mit
45
master
884
class NotifyPuSHHubBodyFeedJob < ApplicationJob queue_as :subscription def perform(body) return if Rails.configuration.x.push_hubs.blank? feed_url = Rails.application.routes.url_helpers.body_feed_url(body: body, format: :atom) urls = [feed_url, "#{feed_url}?feedformat=twitter"] hubs = Rails.confi...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/import_new_papers_job.rb
Ruby
mit
45
master
3,286
class ImportNewPapersJob < ApplicationJob queue_as :import def self.perform_async(body, legislative_term) result = body.scraper_results.create params = [body, legislative_term, result] send(:perform_later, *params) result.to_param end # NOTE: after_perform must be before around_perform, else @...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/reimport_papers_pdf_job.rb
Ruby
mit
45
master
636
class ReimportPapersPDFJob < ApplicationJob queue_as :meta DISTANCE = 5.days STATES = { 'BT' => '%Korrektur\nDrucksache%', 'HB' => '%Vorläufige, unredigierte Fassung%' } def perform STATES.each do |state, like_query| body = Body.find_by_state(state) papers = Paper.where(body: body).w...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/instant_import_new_papers_job.rb
Ruby
mit
45
master
1,938
class InstantImportNewPapersJob < ApplicationJob queue_as :import def self.perform_async(body, legislative_term) result = body.scraper_results.create params = [body, legislative_term, result] send(:perform_later, *params) result.to_param end # NOTE: after_perform must be before around_perform,...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/extract_last_modified_from_paper_job.rb
Ruby
mit
45
master
1,428
class ExtractLastModifiedFromPaperJob < PaperJob queue_as :meta def perform(paper) logger.info "Extracting Last-Modified from Paper [#{paper.body.state} #{paper.full_reference}]" if !Rails.configuration.x.tika_server.blank? last_modified = extract_tika(paper) else last_modified = extract_l...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/contains_classified_information_job.rb
Ruby
mit
45
master
688
class ContainsClassifiedInformationJob < PaperJob queue_as :meta def perform(paper) logger.info "Looking for classified marked Answers in Paper [#{paper.body.state} #{paper.full_reference}]" fail "No Text for Paper [#{paper.body.state} #{paper.full_reference}]" if paper.contents.blank? options = {} ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/reimport_hessen_papers_pdf_job.rb
Ruby
mit
45
master
461
class ReimportHessenPapersPDFJob < ApplicationJob queue_as :meta DISTANCE = 14.days def perform body = Body.find_by_state('HE') papers = Paper.where(body: body).where(['pdf_last_modified < ?', Date.today - DISTANCE]).where(contents: nil) papers.find_each do |paper| logger.info "Adding reimpor...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/extract_related_papers_job.rb
Ruby
mit
45
master
5,177
class ExtractRelatedPapersJob < PaperJob queue_as :meta DIFFERENT_NUMBER_STATES = ['NW', 'RP', 'BB'] def perform(paper) logger.info "Extracting related Papers from Paper [#{paper.body.state} #{paper.full_reference}]" count = 0 if !paper.contents.blank? references = self.class.extract_content...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/store_paper_pdf_job.rb
Ruby
mit
45
master
3,486
class StorePaperPDFJob < PaperJob queue_as :store def perform(paper, options = {}) options.reverse_merge!(force: false) logger.info "Downloading PDF for Paper [#{paper.body.state} #{paper.full_reference}]" fail 'AppStorage: Bucket not available!' if AppStorage.bucket.nil? if !AppStorage.bucket.fi...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/contains_table_job.rb
Ruby
mit
45
master
694
class ContainsTableJob < PaperJob queue_as :meta def perform(paper) logger.info "Looking for Tables in Paper [#{paper.body.state} #{paper.full_reference}]" fail "No Text for Paper [#{paper.body.state} #{paper.full_reference}]" if paper.contents.blank? options = {} options[:skip] = [:looks_like_ta...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/extract_text_from_paper_job.rb
Ruby
mit
45
master
5,021
class ExtractTextFromPaperJob < PaperJob queue_as :meta def perform(paper, options = {}) options.reverse_merge!(method: :all) logger.info "Extracting Text of the Paper [#{paper.body.state} #{paper.full_reference}]" text = nil methods = [:tika, :ocrspace, :local] methods = [options[:method]] un...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/jobs/thumbnail_first_page_job.rb
Ruby
mit
45
master
1,120
class ThumbnailFirstPageJob < PaperJob queue_as :store def perform(paper, options = {}) options.reverse_merge!(force: false) logger.info "Creating thumbnail of first page of the Paper [#{paper.body.state} #{paper.full_reference}]" fail 'AppStorage: Bucket not available!' if AppStorage.bucket.nil? ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/hessen_pdf_extractor.rb
Ruby
mit
45
master
1,955
class HessenPDFExtractor def initialize(paper) @contents = paper.contents end # und\n+Antwort\s+\n+\s+des Ministers für Wirtschaft, Energie, Verkehr und Landesentwicklung\n+ # und\s+\n\n\nAntwort\s+\n\n\ndes Ministers für Soziales und Integration\n+ # und\s+\n+Antwort\s+\n+der Ministerin für Bundes- und ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/hamburg_pdf_has_answer_extractor.rb
Ruby
mit
45
master
261
class HamburgPDFHasAnswerExtractor def initialize(paper) @contents = paper.contents end ANSWERED_TAG = /und\s+Antwort\s+des\s+Senats\s+Betr\.?\:?/i def is_answer? return nil if @contents.nil? @contents.scan(ANSWERED_TAG).present? end end
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/saarland_pdf_extractor.rb
Ruby
mit
45
master
1,389
class SaarlandPDFExtractor def initialize(paper) @contents = paper.contents end PEOPLE = /Anfrage\s+de[rs]\s+Abgeordneten\s+([^\(]+)\s+\(([^\)]+)\)/m PARTY = /Anfrage\s+der(?:(?!\s*Abgeordneten|\s*Fragesteller).)(.*)-Landtagsfraktion/m IS_MAJOR = /W\s?O\s?R\s?T\s+.+?\s+zu\sder\s+[gG]roßen\sAnfrage/m ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/bundestag_pdf_extractor.rb
Ruby
mit
45
master
2,107
class BundestagPDFExtractor def initialize(paper) @contents = paper.contents end ORIGINATORS = /der Abgeordneten (.+?)(?:,\s+weiterer\s+Abgeordneter)?\s+und\s+der\s+Fraktion\s+(?:der\s+)?(.{0,30}?)\.?\n/m ORIGINATORS_GROUPS = /der Fraktionen\s+(?:der\s+)?([^\n]+)\n/m DIVIDER = /V\s*o\s*r\s*b\s*e\s*m\s*e...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/meck_pomm_pdf_extractor.rb
Ruby
mit
45
master
1,167
class MeckPommPDFExtractor def initialize(paper) @contents = paper.contents end # Der Minister für Bildung, Wissenschaft und Kultur hat namens der Landesregierung die Kleine Anfrage mit ANSWERERS = /\s*(?:Der|Die)\s+(Minister.+?.*)(?:\shat\s+namens\s+der\s+Landesregierung\s+die)\s+(?:[kK]leine|[gG]roße)?\...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/schleswig_holstein_pdf_extractor.rb
Ruby
mit
45
master
728
class SchleswigHolsteinPDFExtractor def initialize(paper) @contents = paper.contents end ANSWERERS = /und\s+Antwort\s+der\s+Landesregierung\s+.[ ]+(.+?)\s+\n\s+/m def extract_answerers return nil if @contents.blank? ministries = [] m = @contents.match(ANSWERERS) return nil if m.nil? ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/nordrhein_westfalen_pdf_extractor.rb
Ruby
mit
45
master
887
class NordrheinWestfalenPDFExtractor def initialize(paper) @contents = paper.contents end ORIGINATORS = /Antwort\s+der\s+Landesregierung\s+auf\s+die\s+[kK]leine\s+Anfrage.+?de[rs]\s+Abgeordneten\s+(.+?)\s+(\p{Lu}+?)\s+Drucksache/m def extract_originators return nil if @contents.nil? people = [] ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/thueringen_pdf_extractor.rb
Ruby
mit
45
master
756
class ThueringenPDFExtractor def initialize(paper) @contents = paper.contents end ORIGINATORS = /A\s+n\s+f\s+r\s+a\s+g\s+e\s+de[rs]\s+Abgeordneten\s+([^\(]+)\s+\(([^\)]+)\)/m def extract_originators return nil if @contents.nil? m = @contents.match(ORIGINATORS) return nil if m.nil? partie...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/sachsen_pdf_extractor.rb
Ruby
mit
45
master
2,623
class SachsenPDFExtractor def initialize(paper) @contents = paper.contents end # from: https://de.wikipedia.org/wiki/S%C3%A4chsische_Staatsregierung MINISTRIES = [ 'Staatskanzlei', 'Staatsministerium für Wirtschaft', 'Staatsministerium für Wirtschaft, Arbeit und Verkehr', 'Staatsministerium...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/pdf_extractor.rb
Ruby
mit
45
master
490
class PDFExtractor MULTIPLE_RELATED_MINISTRIES = /((?:Staats)?[mM]inisterium.*?)\s?(?:(?:,|,\s+sowie|sowie|und\s+mit|und|mit)\s+dem\s+((?:Staats)?[mM]inisterium.+))+$/m def self.split_ministries(text) ministries = text.match(MULTIPLE_RELATED_MINISTRIES) return [text] unless ministries results = [] ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/mv_pdf_has_answer_extractor.rb
Ruby
mit
45
master
251
class MvPDFHasAnswerExtractor def initialize(paper) @contents = paper.contents end DUE_DATE_TAG = /\(Termin zur Beantwortung.*gemäß.*\)/m def is_answer? return nil if @contents.nil? @contents.scan(DUE_DATE_TAG).blank? end end
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/brandenburg_pdf_extractor.rb
Ruby
mit
45
master
2,555
class BrandenburgPDFExtractor def initialize(paper) @contents = paper.contents end # Namens der Landesregierung beantwortet die Ministerin für Wissenschaft, Forschung und Kultur die Kleine Anfrage wie folgt: # Namens der Landesregierung beantwortet die Ministerin für Arbeit, Soziales, Ge-\nsundheit, Frauen...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/name_party_extractor.rb
Ruby
mit
45
master
3,199
class NamePartyExtractor NAME_BRACKET_PARTY = :nbp NAME_PARTY_COMMA = :npc REVERSED_NAME_PARTY = :rnp FRACTION = :fraction def initialize(text, format = NAME_BRACKET_PARTY) @text = text @format = format end def extract case @format when NAME_BRACKET_PARTY then extract_nbp when NAME_P...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/baden_wuerttemberg_pdf_extractor.rb
Ruby
mit
45
master
2,552
class BadenWuerttembergPDFExtractor < PDFExtractor def initialize(paper) @contents = paper.contents @doctype = paper.doctype @title = paper.title end ORIGINATORS_MINOR = /Kleine\s+Anfrage\s+de(?:r|s)\s+Abg.\s+(.+?)\s+und\s+Antwort/m ORIGINATORS_MAJOR = /Große\s+Anfrage\s+der\s+Fraktion\s+der\s+(.+?...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/bayern_pdf_extractor.rb
Ruby
mit
45
master
3,631
class BayernPDFExtractor < PDFExtractor def initialize(paper) @contents = paper.contents end def extract_originators return nil if @contents.nil? people = [] parties = [] [ /Abgeordneten ([\D\n]+?)\s(\p{Lu}[\p{Lu} \d\/\n]+)\b/m, /Abgeordneten ([\D\n]+?)\s(\p{Lu}[\p{Lu} \d\/]+)\b/m...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/rheinland_pfalz_pdf_extractor.rb
Ruby
mit
45
master
557
class RheinlandPfalzPDFExtractor def initialize(paper) @contents = paper.contents end ORIGINATORS = /K\s*l\s*e\s*i\s*n\s*e\s*A\s*n\s*f\s*r\s*a\s*g\s*e\n\nde[rs]\s+Abgeordneten\s+(.+?)\n\nund\s+A\s*n\s*t\s*w\s*o\s*r\s*t/m def extract_originators return nil if @contents.nil? m = @contents.match(ORI...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/berlin_pdf_extractor.rb
Ruby
mit
45
master
858
class BerlinPDFExtractor def initialize(paper) @contents = paper.contents end # \n.................................\nSenatsverwaltung für Stadtentwicklung und Umwelt\n # \n_____________________________\nSenatsverwaltung für Gesundheit und Soziales\n ANSWERERS = /\n[\.\_]{28,40}\s+(Senatsverwaltung\s+.+?)...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/extractors/bremen_pdf_extractor.rb
Ruby
mit
45
master
1,822
class BremenPDFExtractor def initialize(paper) @contents = paper.contents @doctype = paper.doctype @title = paper.title end ORIGINATORS = /\d+.+[\?\.\\](?:\n\n(.+?)\s+und\s+Fraktion\s+[^\n]+)(?:\n\n(.+?)\s+und\s+Fraktion\s+[^\n]+)*.+(?:Antwort\s+des\s+Senats|Der\s+Senat\s+beantwortet)/m FACTIONS_WI...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/validators/email_validator.rb
Ruby
mit
45
master
224
class EmailValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i record.errors.add(attribute, :invalid) end end end
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/controllers/review_controller.rb
Ruby
mit
45
master
3,297
class ReviewController < ApplicationController def index end def papers @incomplete = {} @count = 0 Body.find_each do |b| @incomplete[b.state] = [] @incomplete[b.state].concat Paper.where(body: b).where(['published_at > ?', Date.today]) @incomplete[b.state].concat Paper.where(body: ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/controllers/ministry_controller.rb
Ruby
mit
45
master
629
class MinistryController < ApplicationController before_action :find_body before_action :find_ministry def show @papers = @ministry.papers .where.not(published_at: nil) .includes(:body, :paper_originators) .order(legislative_term: :desc, published_at: :desc, referenc...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/controllers/legislative_term_controller.rb
Ruby
mit
45
master
764
class LegislativeTermController < ApplicationController before_action :find_body before_action :find_legislative_term def show redirect_to(body_feed_url(@body, format: :atom), status: :moved_permanently) if params[:format] == 'atom' @papers = @legislative_term.papers .where.not(published_a...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/controllers/organization_controller.rb
Ruby
mit
45
master
672
class OrganizationController < ApplicationController before_action :find_body before_action :find_organization def show @papers = @organization.papers .where(body: @body) .where.not(published_at: nil) .includes(:body, :paper_originators) .order(legislat...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/controllers/info_controller.rb
Ruby
mit
45
master
200
class InfoController < ApplicationController def daten end def mitmachen end def kontakt end def datenschutz end def spenden end def index end def stilllegung end end
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/controllers/site_controller.rb
Ruby
mit
45
master
527
class SiteController < ApplicationController def index @bodies = Body.order("state != 'BT', name ASC").all @papers = Paper .where.not(published_at: nil) .limit(11) .includes(:body, :paper_originators) .order(published_at: :desc, reference: :desc) @co...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/controllers/body_controller.rb
Ruby
mit
45
master
711
class BodyController < ApplicationController before_action :find_body def show @terms = @body.legislative_terms @scraper_result = @body.scraper_results.where.not(stopped_at: nil).order(stopped_at: :desc).first @latest_paper = @body.papers.where.not(published_at: nil).order(published_at: :desc).first ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/controllers/scraper_results_controller.rb
Ruby
mit
45
master
667
class ScraperResultsController < ApplicationController before_action :find_scraper_result, only: [:show] def index @bodies = Body.all @results = {} @dates = ((Date.today - 10.days)..Date.today).to_a @bodies.each do |body| scraper_results = body.scraper_results.where(['created_at > ?', @dates....
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/controllers/search_controller.rb
Ruby
mit
45
master
7,176
class SearchController < ApplicationController PARAMS_TO_CONVERT = %w(table classified body doctype faction pages published_at) SUPPORTED_PARAMS = %w(q page sort) + PARAMS_TO_CONVERT ALLOWED_SORT_FIELDS = %w(published_at pages full_reference) def search @query = params[:q].presence redirect_to(root_url...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/controllers/metrics_controller.rb
Ruby
mit
45
master
1,409
class MetricsController < ApplicationController METRIC = Struct.new(:key, :value) def show stats = Sidekiq::Stats.new metrics = [] # papers_all_count metrics << m('papers_all_count', Paper.count) # ministries_all_count metrics << m('ministries_all_count', Ministry.count) # papers_bod...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/controllers/application_controller.rb
Ruby
mit
45
master
598
class ApplicationController < ActionController::Base # kleineAnfragen is sessionless. # So the following line is commented out: # protect_from_forgery with: :null_session # make request_id available to lograge # see other part in config/application.rb def append_info_to_payload(payload) super paylo...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/controllers/paper_controller.rb
Ruby
mit
45
master
2,648
class PaperController < ApplicationController before_action :find_body, only: [:show, :viewer, :report, :send_report, :update] before_action :find_legislative_term, only: [:show, :viewer, :report, :send_report, :update] before_action :find_paper, only: [:show, :viewer, :report, :send_report, :update] before_act...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/helpers/application_helper.rb
Ruby
mit
45
master
1,693
module ApplicationHelper def link_to_paper_url(title, paper, html_options = {}) link_to title, paper_url(paper.body, paper.legislative_term, paper), html_options end def link_to_paper(title, paper, html_options = {}) link_to title, paper_path(paper.body, paper.legislative_term, paper), html_options end...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/helpers/search_helper.rb
Ruby
mit
45
master
630
module SearchHelper def facet_count(key, term) terms = @papers.aggs.try(:[], key).try(:fetch, 'buckets', nil) terms.find { |el| el['key'] == term }.try(:fetch, 'doc_count', nil) unless terms.nil? end def write_facet_count(key, term) count = facet_count(key, term) count.present? ? "(#{number_with_...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
app/helpers/scraper_results_helper.rb
Ruby
mit
45
master
1,036
module ScraperResultsHelper def distance_of_time_in_min_sec(from_time, to_time = nil) to_time = Time.now if to_time.nil? from_time = from_time.to_time if from_time.respond_to?(:to_time) to_time = to_time.to_time if to_time.respond_to?(:to_time) from_time, to_time = to_time, from_time if from_time > to...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
lib/es_query_parser.rb
Ruby
mit
45
master
2,272
class EsQueryParser def self.convert_date_range(text) r = parse_range(text) return nil if r.nil? convert_date = ->(value) do if value.size == 4 && value.to_i.to_s == value # looks like a year value else # everything else Date.parse(value).to_s end end...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
lib/classified_recognizer.rb
Ruby
mit
45
master
1,834
class ClassifiedRecognizer attr_accessor :skip attr_reader :text attr_writer :debug def initialize(text, debug: false, skip: nil) @text = text @debug = debug @skip = skip || [] end def debug? @debug end def recognize throw 'No text set' if @text.nil? @probability = 0.0 @g...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
lib/nomenklatura.rb
Ruby
mit
45
master
4,215
# # Simple Nomenklatura (https://github.com/pudo/nomenklatura) API client # Only for API version 2, so only master # Based on the https://github.com/pudo/pynomenklatura Python API client # module Nomenklatura class Client include HTTParty format :json def initialize(options = {}) options = { api_pr...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
lib/table_recognizer.rb
Ruby
mit
45
master
2,894
class TableRecognizer attr_accessor :skip attr_reader :text attr_writer :debug def initialize(text, debug: false, skip: nil) @text = text @debug = debug @skip = skip || [] end def debug? @debug end def recognize throw 'No text set' if @text.nil? @probability = 0.0 @groups...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
lib/paper_importer.rb
Ruby
mit
45
master
2,713
class PaperImporter attr_accessor :logger def initialize(body) @body = body @load_details = @body.scraper.const_defined?(:Detail) @logger ||= Rails.logger end def import(item) new_paper = false # we know that answered paper already? skip. # FIXME: maybe it should be diffed / update em...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
lib/tasks/papers.rake
Ruby
mit
45
master
4,929
namespace :papers do desc 'switch logger to stdout' task to_stdout: :environment do Rails.logger = Logger.new(STDOUT) end desc 'Download and store papers in s3' task store_all: :environment do limit = ENV['limit'] || 50 papers = Paper.where(downloaded_at: nil).limit(limit) papers.find_each do...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
config/application.rb
Ruby
mit
45
master
3,646
require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module Kleineanfragen class Application < Rails::Application # Initialize configuration defaults for originally generated ...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
config/routes.rb
Ruby
mit
45
master
3,209
require 'sidekiq/web' Rails.application.routes.draw do # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". sidekiq_web_constraint = ->(_, request) { ['::1', '127.0.0.1'].include?(request.remote_ip) || ENV['SIDEKIQ_SERVER_OPEN']....
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
config/puma.rb
Ruby
mit
45
master
2,328
# Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
config/environments/test.rb
Ruby
mit
45
master
2,122
Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suit...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
config/environments/development.rb
Ruby
mit
45
master
2,691
Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web serv...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
config/environments/production.rb
Ruby
mit
45
master
4,512
Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web serve...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
config/initializers/friendly_id.rb
Ruby
mit
45
master
3,156
# FriendlyId Global Configuration # # Use this to set up shared configuration options for your entire application. # Any of the configuration options shown here can also be applied to single # models by passing arguments to the `friendly_id` class method or defining # methods in your model. # # To learn more, check out...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
config/initializers/grape_route_helpers_multiple_paths_monkeypatch.rb
Ruby
mit
45
master
434
# # Monkeypatching grape-route-helpers to support multiple routes in one resource # # Source: # https://github.com/reprah/grape-route-helpers/pull/13 # module GrapeRouteHelpers module AllRoutes def all_routes routes = subclasses.flat_map { |s| s.send(:prepare_routes) } routes.uniq do |r| if r....
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
config/initializers/mechanize_http_agent_monkeypatch.rb
Ruby
mit
45
master
1,843
# # Source: # http://scottwb.com/blog/2013/11/09/defeating-the-infamous-mechanize-too-many-connection-resets-bug/ # class Mechanize::HTTP::Agent MAX_RESET_RETRIES = 3 # We need to replace the core Mechanize HTTP method: # # Mechanize::HTTP::Agent#fetch # # with a wrapper that handles the infamous "too ma...
github
robbi5/kleineanfragen
https://github.com/robbi5/kleineanfragen
config/initializers/overrides.rb
Ruby
mit
45
master
401
# ActiveJob-Retry is calling `ActiveJob::Base.queue_adapter.name` # https://github.com/isaacseymour/activejob-retry/blob/33b9b5dc4c04cd8127e67c8682228b710c93189e/lib/active_job/retry.rb#L105 # # this doesn't work, but we're also not using one of those "PROBLEMATIC_ADAPTERS" # so simply remove it. # module ActiveJob c...