Exemplo n.º 1
0
def suche_feed():
  start_time = time.time()
  jsonp_callback = request.args.get('callback', None)
  q = request.args.get('q', '*:*')
  fq = request.args.get('fq', '')
  date_param = request.args.get('date', '')
  region = request.args.get('r', app.config['region_default'])
  
  # Suche wird durchgeführt
  query = db.query_paper(region=region, q=q, fq=fq, sort='publishedDate:desc', start=0,
             papers_per_page=50, facets=False)
  
  # Generate Root and Metainfos
  search_url = "%s/suche/?r=%s&q=%s&fq=%s" % (app.config['base_url'], region, q, fq)
  feed_url = "%s/suche/feed/?r=%s&q=%s&fq=%s" % (app.config['base_url'], region, q, fq)
  root = etree.Element("rss", version="2.0", nsmap={'atom': 'http://www.w3.org/2005/Atom'})
  channel = etree.SubElement(root, "channel")
  etree.SubElement(channel, "title").text = 'Offenes Ratsinformationssystem: Paper-Feed'
  etree.SubElement(channel, "link").text = search_url
  etree.SubElement(channel, "language").text = 'de-de'
  description = u"Neue oder geänderte Dokumente mit dem Suchbegriff %s in %s" % (q, app.config['regions'][region]['name'])
  # TODO: Einschränkungen mit in die Description
  if fq:
    description += ''
  etree.SubElement(channel, "description").text = description
  etree.SubElement(channel, '{http://www.w3.org/2005/Atom}link', href=feed_url, rel="self", type="application/rss+xml")
  
  # Generate Result Items
  for paper in query['result']:
    item = etree.SubElement(channel, "item")
    paper_link = "%s/paper/%s" % (app.config['base_url'], paper['id'])
    description = 'Link: ' + paper_link + '</br>'
    if 'paperType' in paper:
      description = 'Art des Papers: ' + paper['paperType'] + '<br />'
    if 'publishedDate' in paper:
      description += u"Erstellt am: %s<br />" % dateutil.parser.parse(paper['publishedDate']).strftime('%d.%m.%Y')
    if 'lastModified' in paper:
      description += u"Zuletzt geändert am: %s<br />" % dateutil.parser.parse(paper['lastModified']).strftime('%d.%m.%Y')
    
    etree.SubElement(item, "pubDate").text = util.rfc1123date(paper['lastModified'] if 'lastModified' in paper else datetime.datetime.now())
    etree.SubElement(item, "title").text = paper['name'] if 'name' in paper else 'Kein Titel'
    etree.SubElement(item, "description").text = description
    etree.SubElement(item, "link").text = paper_link
    etree.SubElement(item, "guid").text = paper_link
  
  response = make_response(etree.tostring(root, pretty_print=True), 200)
  response.mimetype = 'application/rss+xml'
  response.headers['Expires'] = util.expires_date(hours=24)
  response.headers['Cache-Control'] = util.cache_max_age(hours=24)
  return response
Exemplo n.º 2
0
def api_papers():
    """
  API-Methode zur Suche von Paper
  """
    start_time = time.time()
    jsonp_callback = request.args.get('callback', None)
    ref = request.args.get('reference', '')
    q = request.args.get('q', '*:*')
    fq = request.args.get('fq', '')
    sort = request.args.get('sort', 'score:desc')
    start = int(request.args.get('start', '0'))
    papers_per_page = int(request.args.get('ppp', '10'))
    date_param = request.args.get('date', '')
    region = request.args.get('r', '')
    output = request.args.get('output', '').split(',')
    get_facets = 'facets' in output
    request_info = {}  # Info über die Anfrage

    # Suche wird durchgeführt
    query = db.query_paper(region=region,
                           q=q,
                           fq=fq,
                           sort=sort,
                           start=start,
                           papers_per_page=papers_per_page,
                           facets=get_facets)

    ret = {
        'status': 0,
        'duration': int((time.time() - start_time) * 1000),
        'request': request_info,
        'response': query
    }

    ret['response']['start'] = start
    ret['request']['sort'] = sort
    ret['request']['fq'] = fq

    json_output = json.dumps(ret, cls=util.MyEncoder, sort_keys=True)
    if jsonp_callback is not None:
        json_output = jsonp_callback + '(' + json_output + ')'
    response = make_response(json_output, 200)
    response.mimetype = 'application/json'
    response.headers['Expires'] = util.expires_date(hours=24)
    response.headers['Cache-Control'] = util.cache_max_age(hours=24)
    return response
Exemplo n.º 3
0
def api_papers():
  """
  API-Methode zur Suche von Paper
  """
  start_time = time.time()
  jsonp_callback = request.args.get('callback', None)
  ref = request.args.get('reference', '')
  q = request.args.get('q', '*:*')
  fq = request.args.get('fq', '')
  sort = request.args.get('sort', 'score:desc')
  start = int(request.args.get('start', '0'))
  papers_per_page = int(request.args.get('ppp', '10'))
  date_param = request.args.get('date', '')
  region = request.args.get('r', '')
  output = request.args.get('output', '').split(',')
  get_facets = 'facets' in output
  request_info = {}  # Info über die Anfrage
  
  # Suche wird durchgeführt
  query = db.query_paper(region=region, q=q, fq=fq, sort=sort, start=start,
             papers_per_page=papers_per_page, facets=get_facets)
  
  ret = {
    'status': 0,
    'duration': int((time.time() - start_time) * 1000),
    'request': request_info,
    'response': query
  }
  
  ret['response']['start'] = start
  ret['request']['sort'] = sort
  ret['request']['fq'] = fq

  json_output = json.dumps(ret, cls=util.MyEncoder, sort_keys=True)
  if jsonp_callback is not None:
    json_output = jsonp_callback + '(' + json_output + ')'
  response = make_response(json_output, 200)
  response.mimetype = 'application/json'
  response.headers['Expires'] = util.expires_date(hours=24)
  response.headers['Cache-Control'] = util.cache_max_age(hours=24)
  return response
Exemplo n.º 4
0
def api_papers():
    """
  API-Methode zur Suche von Paper
  """
    start_time = time.time()
    jsonp_callback = request.args.get("callback", None)
    ref = request.args.get("reference", "")
    q = request.args.get("q", "*:*")
    fq = request.args.get("fq", "")
    sort = request.args.get("sort", "score:desc")
    start = int(request.args.get("start", "0"))
    papers_per_page = int(request.args.get("ppp", "10"))
    date_param = request.args.get("date", "")
    region = request.args.get("r", "")
    output = request.args.get("output", "").split(",")
    get_facets = "facets" in output
    request_info = {}  # Info über die Anfrage

    # Suche wird durchgeführt
    query = db.query_paper(
        region=region, q=q, fq=fq, sort=sort, start=start, papers_per_page=papers_per_page, facets=get_facets
    )

    ret = {"status": 0, "duration": int((time.time() - start_time) * 1000), "request": request_info, "response": query}

    ret["response"]["start"] = start
    ret["request"]["sort"] = sort
    ret["request"]["fq"] = fq

    json_output = json.dumps(ret, cls=util.MyEncoder, sort_keys=True)
    if jsonp_callback is not None:
        json_output = jsonp_callback + "(" + json_output + ")"
    response = make_response(json_output, 200)
    response.mimetype = "application/json"
    response.headers["Expires"] = util.expires_date(hours=24)
    response.headers["Cache-Control"] = util.cache_max_age(hours=24)
    return response
Exemplo n.º 5
0
def suche_feed():
    start_time = time.time()
    jsonp_callback = request.args.get('callback', None)
    q = request.args.get('q', '*:*')
    fq = request.args.get('fq', '')
    date_param = request.args.get('date', '')
    region = request.args.get('r', app.config['region_default'])

    # Suche wird durchgeführt
    query = db.query_paper(region=region,
                           q=q,
                           fq=fq,
                           sort='publishedDate:desc',
                           start=0,
                           papers_per_page=50,
                           facets=False)

    # Generate Root and Metainfos
    search_url = "%s/suche/?r=%s&q=%s&fq=%s" % (app.config['base_url'], region,
                                                q, fq)
    feed_url = "%s/suche/feed/?r=%s&q=%s&fq=%s" % (app.config['base_url'],
                                                   region, q, fq)
    root = etree.Element("rss",
                         version="2.0",
                         nsmap={'atom': 'http://www.w3.org/2005/Atom'})
    channel = etree.SubElement(root, "channel")
    etree.SubElement(
        channel, "title").text = 'Offenes Ratsinformationssystem: Paper-Feed'
    etree.SubElement(channel, "link").text = search_url
    etree.SubElement(channel, "language").text = 'de-de'
    description = u"Neue oder geänderte Dokumente mit dem Suchbegriff %s in %s" % (
        q, app.config['regions'][region]['name'])
    # TODO: Einschränkungen mit in die Description
    if fq:
        description += ''
    etree.SubElement(channel, "description").text = description
    etree.SubElement(channel,
                     '{http://www.w3.org/2005/Atom}link',
                     href=feed_url,
                     rel="self",
                     type="application/rss+xml")

    # Generate Result Items
    for paper in query['result']:
        item = etree.SubElement(channel, "item")
        paper_link = "%s/paper/%s" % (app.config['base_url'], paper['id'])
        description = 'Link: ' + paper_link + '</br>'
        if 'paperType' in paper:
            description = 'Art des Papers: ' + paper['paperType'] + '<br />'
        if 'publishedDate' in paper:
            description += u"Erstellt am: %s<br />" % dateutil.parser.parse(
                paper['publishedDate']).strftime('%d.%m.%Y')
        if 'modified' in paper:
            description += u"Zuletzt geändert am: %s<br />" % dateutil.parser.parse(
                paper['modified']).strftime('%d.%m.%Y')

        etree.SubElement(item, "pubDate").text = util.rfc1123date(
            paper['modified'] if 'modified' in
            paper else datetime.datetime.now())
        etree.SubElement(
            item,
            "title").text = paper['name'] if 'name' in paper else 'Kein Titel'
        etree.SubElement(item, "description").text = description
        etree.SubElement(item, "link").text = paper_link
        etree.SubElement(item, "guid").text = paper_link

    response = make_response(etree.tostring(root, pretty_print=True), 200)
    response.mimetype = 'application/rss+xml'
    response.headers['Expires'] = util.expires_date(hours=24)
    response.headers['Cache-Control'] = util.cache_max_age(hours=24)
    return response