コード例 #1
0
def postEmail():
    """Inserts an email into the list. request.args: 
      email: mandatory
    """
    m = HomeModel()
    return (jsonify({"email": m.newEmail(request.args["email"])}))
コード例 #2
0
ファイル: home.py プロジェクト: GeographicaGS/Elcano-iepg
def postEmail():
    """Inserts an email into the list. request.args: 
      email: mandatory
    """
    m = HomeModel()
    return(jsonify({"email": m.newEmail(request.args["email"])}))
コード例 #3
0
def newStuff():
    """Returns new stuff for the new stuff control. Accepts request.args:

      lang=en/es: mandatory 
      section= 1=Blog/2=Media/3=Events/4=Documents/5=Twitter: optional. If absent, sends
      all sections mixed

    Returns a JSON in the form:

    {
        "news":[{
    	    "id": "1",
    	    "wwwuser": "******",
    	    "time": "201401101027",
	    "title": "¿El auge del resto? Apuntes sobre la presencia
	    global de América Latina, Asia y el Magreb y Oriente Medio",
            "link": "http://www.geographica.gs",
    	    "section": "Blog",
    	    "labels": [
                {"id": "1", "label": "IEPG"},
    	        {"id": "2", "label": "Economía"}]
        }]
    }

    TODO: revisar, devuelve unos id un poco raros
    """
    m = HomeModel()
    l = LabelModel()
    lang = request.args["lang"]
    section = int(
        request.args["section"]) if "section" in request.args else None

    try:
        labels = l.getLabels(lang)
        if section:
            if section in [1, 2, 3]:
                stuff = m.newStuffSections(lang, section)
            elif section == 4:
                stuff = m.newStuffDocuments(lang)
            elif section == 5:
                timeline = helpers.twitterGetLatestTweets()
                stuff = []
                for tweet in timeline:
                    stuff.append({
                        "id": tweet.id,
                        "time": tweet.created_at,
                        "title": tweet.text,
                        "section": "Twitter",
                        "labels": [],
                        "wwwuser": "******"
                    })
            else:
                e = ElcanoErrorBadNewsSection(section)
                return (jsonify(e.dict()))
        else:
            stuff = m.newStuffAll(lang)
    except ElcanoError as e:
        return (jsonify(e.dict()))

    for s in stuff:
        lab = []
        if s["labels"] != [None]:
            for l in s["labels"]:
                for a in labels:
                    if str(a["id"]) == str(l):
                        lab.append(a)

        s["labels"] = lab
        s["time"] = str(s["time"].isoformat())

    return (jsonify({"results": stuff}))
コード例 #4
0
ファイル: home.py プロジェクト: GeographicaGS/Elcano-iepg
def newStuff():
    """Returns new stuff for the new stuff control. Accepts request.args:

      lang=en/es: mandatory 
      section= 1=Blog/2=Media/3=Events/4=Documents/5=Twitter: optional. If absent, sends
      all sections mixed

    Returns a JSON in the form:

    {
        "news":[{
    	    "id": "1",
    	    "wwwuser": "******",
    	    "time": "201401101027",
	    "title": "¿El auge del resto? Apuntes sobre la presencia
	    global de América Latina, Asia y el Magreb y Oriente Medio",
            "link": "http://www.geographica.gs",
    	    "section": "Blog",
    	    "labels": [
                {"id": "1", "label": "IEPG"},
    	        {"id": "2", "label": "Economía"}]
        }]
    }

    TODO: revisar, devuelve unos id un poco raros
    """
    m = HomeModel()
    l = LabelModel()
    lang = request.args["lang"]
    section = int(request.args["section"]) if "section" in request.args else None

    try:
        labels = l.getLabels(lang)
        if section:
            if section in [1,2,3]:
                stuff = m.newStuffSections(lang, section)
            elif section==4:
                stuff = m.newStuffDocuments(lang)
            elif section==5:
                timeline = helpers.twitterGetLatestTweets()
                stuff = []
                for tweet in timeline:
                    stuff.append({
                        "id" : tweet.id,
                        "time" : tweet.created_at,
                        "title" : tweet.text,
                        "section" : "Twitter",
                        "labels" :[],
                        "wwwuser" : "@rielcano"
                    })
            else:
                e = ElcanoErrorBadNewsSection(section)
                return(jsonify(e.dict()))
        else:
            stuff = m.newStuffAll(lang)
    except ElcanoError as e:
        return(jsonify(e.dict()))

    for s in stuff:
        lab = []
        if s["labels"]!=[None]:
            for l in s["labels"]:
                for a in labels:
                    if str(a["id"])==str(l):
                        lab.append(a)

        s["labels"] = lab
        s["time"] = str(s["time"].isoformat())

    return(jsonify({"results": stuff}))