Ejemplo n.º 1
0
def getClustersServer():

    category = request.args.get('category')

    str = ''

    clusters = Cluster.query(Cluster.category == category).fetch()

    str += 'Got category %s\n' % category

    if clusters is None:
        str = 'None clusters :/'
    else:
        i = 1

        str += 'Number of clusters %d\n' % len(clusters)

        for c in clusters:
            str += 'Cluster %d\n' % i

            for np in c.listNews:
                str += '\t%s\t%s\n' % (np.title, np.source_url)

            i += 1


    return Response(str, mimetype='text/plain')
Ejemplo n.º 2
0
def  getClustersWithCat():
    feedback = ''
    str = ''
    try:
        category = request.args.get('category')

        str += 'got parameter category: %s\n' % category
        clusters = Cluster.query(Cluster.category == category).fetch()
        str += 'fetched the clusters'
        str = ''
        i = 1
        for c in clusters:
            str += 'cluster %d:\n' % i
            str += 'category: %s\n' % c.category


            for np in c.listNews:
                str += '\t%s\n' % np.title


            str += '\n'


            i+= 1

    except Exception as inst:
            feedback += 'Exception type: %s\n' % type(inst)
            feedback += 'Exception: %s\n' % inst.message

    str += feedback

    return Response(str, mimetype='text/plain')
Ejemplo n.º 3
0
def prepareClustering():
    logging.debug('preparing for refreshing..')
    ndb.delete_multi(Cluster.query().fetch(keys_only=True))

    getClusters()
    logging.debug('refreshed!')

    return ''
Ejemplo n.º 4
0
def getMYClusters():
    category = request.args.get('category')

    clusters = Cluster.query(Cluster.category == category).fetch()

    obj = {'listClusters' : [c.serialize() for c in clusters]}

    result = json.dumps(obj, ensure_ascii=True)

    return Response(result, mimetype='text/plain')
Ejemplo n.º 5
0
def getFilteredClustersDebug():
    reqParam = request.args.get('wantedSources')
    listWanted = []


    #vrednosta na parametarot wantedSources kje bide od oblik id1,id2


    if None != reqParam:
        listWanted = reqParam.split(',')

    # da se pretvorat vo integers
    for i in range(0, len(listWanted)):
        listWanted[i] = int(listWanted[i])

    result = 'Wanted sources: %s\n' % listWanted



    category = request.args.get('category')

    clusters = Cluster.query(Cluster.category == category).fetch()


    #tuka gi smestuvame samo klasterite shto se so filtrirani vesti
    # (ne zemame vesti od izvori sto korisnikot ne gi saka)
    clustersToReturn = []

    for c in clusters:
        listNews = []
        for np in c.listNews:
            if np.source_id in listWanted:
                listNews.append(np)
        #dokolku klasterot nema nitu edna vest posle filtriranjeto
        #ne go vkluchuvame bidejkji e prazen :)
        if len(listNews) > 0:
            c.listNews = listNews
            clustersToReturn.append(c)



    i = 1

    #debugging
    result += 'Number of clusters %d\n' % len(clusters)
    
    for c in clustersToReturn:
        result += 'Cluster %d\n' % i
        for np in c.listNews:
            result += '\t%s\t%s\n' % (np.title, np.source_url)
        i += 1



    return Response(result, mimetype='text/plain')
Ejemplo n.º 6
0
def getMYNews():
    category = request.args.get('category')
    news = NewsPost.query().fetch()
    clusters = Cluster.query(Cluster.category == category).fetch()

    newNews = []

    for n in news:
        newObject = NewsPostClient(url = n.url,host_page = n.host_page,title = n.title, description = n.description)
        newNews.append(newObject)


    #result = str(byteify(newNews[0].serialize()))

    result = ''


    return Response(result, mimetype='application/javascript')
Ejemplo n.º 7
0
def getFilteredClusters():

    reqParam = request.args.get('wantedSources')

    listWanted = []

    if None != reqParam:
        listWanted = reqParam.split(',')


    for i in range(0, len(listWanted)):
        listWanted[i] = int(listWanted[i])

    category = request.args.get('category')

    clusters = Cluster.query(Cluster.category == category).fetch()

    clustersToReturn = []

    for c in clusters:
        listNews = []
        for np in c.listNews:
            if np.source_id in listWanted:
                listNews.append(np)

        if len(listNews) > 0:
            c.listNews = listNews
            clustersToReturn.append(c)


    # WE NEED TO SORT THE CLUSTERS BY SOME PARAMETER (MAYBE THE SIZE OF THE CLUSTER)

    obj = {'listClusters' : [c.serialize() for c in clustersToReturn]}

    result = json.dumps(obj, ensure_ascii=True)

    return Response(result, mimetype='text/plain')