Ejemplo n.º 1
0
def update_url(user, keyword, url, investment, ip):
	tag = TallstreetTags.getKeyName(keyword)
	dbkeyword = TallstreetTags.get_or_insert(tag)
	if not(dbkeyword.tag):
		dbkeyword.tag = keyword
		dbkeyword.count = 1
	else:
		dbkeyword.count += 1			
	change = update_portfolio(user, dbkeyword, url, investment, ip)
	if change == 0:
		return
	
	dbuniverse = TallstreetUniverse.get_universe(dbkeyword, url)
				
	if dbuniverse:
		dbuniverse.money += change
	else:
		dbuniverse = TallstreetUniverse.get_or_insert("universe%s%s" % (dbkeyword.key(), url.key()))
		dbuniverse.money = change
		dbuniverse.tag = dbkeyword
		dbuniverse.url = url

	if dbuniverse.money == 0:
		dbuniverse.delete()
		dbkeyword.count -= 1	
	else:		
		dbuniverse.put()
	dbkeyword.put()
Ejemplo n.º 2
0
def view(request, category, page=1):
    category = category.replace("_", " ")
    tagdata = TallstreetTags.get(category)
    payload = {}
    size = 10
    page = int(page)

    payload["page"] = page
    payload["size"] = size
    payload["search"] = category
    payload["results2"] = []

    if tagdata and tagdata.count > 30:
        payload["hits"] = tagdata.count
        payload["results"] = get_local_results(int((page - 1) * size), size, tagdata, request.user)
    elif tagdata:
        offset = int((page - 1) * size)
        if offset < tagdata.count and offset + size <= tagdata.count:
            # just a random number of hits (not worth querying yahoo to get exact number)
            payload["hits"] = tagdata.count + 19223211
            payload["results"] = get_local_results(offset, size, tagdata, request.user)
        elif offset < tagdata.count and offset + size > tagdata.count:
            localresults = tagdata.count - offset
            payload["results"] = get_local_results(offset, localresults, tagdata, request.user)
            (hits, results) = get_boss_results(0, size - localresults, category)
            payload["hits"] = tagdata.count + hits
            payload["results2"] = results
        else:
            (hits, payload["results"]) = get_boss_results(offset - tagdata.count, size, category)
            payload["hits"] = tagdata.count + hits
    else:
        (payload["hits"], payload["results"]) = get_boss_results(int((page - 1) * size), size, category)

    payload["results_per_page"] = size
    payload["last_on_page"] = page * size
    payload["page"] = page
    if payload["hits"] > size:
        payload["pages"] = ((payload["hits"] - size) / payload["results_per_page"]) + 2
    else:
        payload["pages"] = 1
    payload["next"] = page + 1
    payload["previous"] = page - 1
    payload["has_next"] = page < payload["pages"]
    payload["has_previous"] = page > 1
    payload["paginator_param"] = "/view/%s/" % category.replace(" ", "_")
    payload["search_text"] = "<a href='%s'>%s</a> - Displaying %s to %s of %s" % (
        payload["paginator_param"],
        category,
        payload["last_on_page"] - size + 1,
        payload["last_on_page"],
        payload["hits"],
    )
    return render(request, "results.html", payload)
Ejemplo n.º 3
0
def dequeuerating(request):
	url = TallstreetUrls.get_url(request.POST['url'])
	if not url:
		logging.debug("no url %s " % request.POST['url'])
		return HttpResponse("No Url", mimetype="text/plain")
	
	keyword = TallstreetTags.get_by_key_name("tag%s" %request.POST['keyword'].lower())
	if not keyword:
		logging.debug("no Keyword")
		return HttpResponse("No Keyword", mimetype="text/plain")
	
	universe = TallstreetUniverse.get_universe(keyword, url)	 
	if not universe:	
		logging.debug("no Universe")		
		return HttpResponse("No Universe", mimetype="text/plain")
	
	historychanges = TallstreetHistoryChanges.get_or_insert(key_name="history%s%s" % (keyword.key(), url.key()))
	ips = historychanges.ips
		
	change = 0
	if request.path == '/queue/click':
		change = 1
	elif request.path == '/queue/rating' and request.POST['rating'] == '5':
		change = 50
	elif request.path == '/queue/rating' and request.POST['rating'] == '4':
		change = 20
	elif request.path == '/queue/rating' and request.POST['rating'] == '3':
		change = 10
	elif request.path == '/queue/rating' and request.POST['rating'] == '2':
		change = 5
	elif request.path == '/queue/rating' and request.POST['rating'] == '1':
		change = -20

	date = datetime.datetime(datetime.datetime.today().year, datetime.datetime.today().month, datetime.datetime.today().day)
	

	if request.POST['ip'] + request.path in ips:
		return HttpResponse("Already Rated", mimetype="text/plain")
	ips.append(request.POST['ip'] + request.path)

	historychanges.ips = ips
	historychanges.change += change
	historychanges.put()
	
	t = Task(url='/queue/calchistory', params={'historychanges': historychanges.key().id_or_name(), 'universe': universe.key().id_or_name()}, name=historychanges.key().id_or_name() + date.strftime('%Y%m%d'), eta=date + datetime.timedelta(days=1))
	logging.debug(t)
	try:
		t.add('historyqueue')
	except TaskAlreadyExistsError:
		pass
	logging.debug("Success")
	return HttpResponse("Success", mimetype="text/plain")
Ejemplo n.º 4
0
def search(request):
    result = TallstreetTags.get(request.GET["query"])
    if result:
        return HttpResponsePermanentRedirect("/view/" + result.tag.replace(" ", "_") + "/")
    else:
        return HttpResponsePermanentRedirect("/view/" + request.GET["query"].replace(" ", "_") + "/")
Ejemplo n.º 5
0
def search(request):
	result = TallstreetTags.get(request.GET['query'])
	if result:
		return HttpResponsePermanentRedirect('/view/' + result.tag.replace(" ", "_") + '/')
	else:
		return HttpResponsePermanentRedirect('/view/' + request.GET['query'].replace(" ", "_") + '/')
Ejemplo n.º 6
0
	def items(self, obj):
		ratings = []
		ips = []
		clicks =  TallstreetClick.get_all()
		history = False
		for click in clicks:
			click.delete()
			logging.debug("Analysing %s %s %s %s %s" % (click.url, click.keyword, click.ip, click.type, click.rating))
			url = TallstreetUrls.get_url(click.url)
			if not url:
				logging.debug("No url")
				continue
			
			keyword = TallstreetTags.get_by_key_name("tag%s" %click.keyword.lower())
			if not keyword:
				logging.debug("No keyword")
				continue
			
			universe = TallstreetUniverse.get_universe(keyword, url)	 
			if not universe:			
				logging.debug("No universe")
				continue 
			
			if ips == []:
				historychanges = TallstreetHistoryChanges.get_or_insert(key_name="history%s%s" % (keyword.key(), url.key()))
				ips = historychanges.ips		
			
			change = 0
			if click.type == 'C':
				change = 1
			elif click.type == 'R' and click.rating == 5:
				change = 50
			elif click.type == 'R' and click.rating == 4:
				change = 20
			elif click.type == 'R' and click.rating == 3:
				change = 10
			elif click.type == 'R' and click.rating == 2:
				change = 5
			elif click.type == 'R' and click.rating == 1:
				change = -20
				
			date = datetime.datetime(click.time.year, click.time.month, click.time.day)
			
			
			if click.ip + click.type in ips:
				continue
			ips.append(click.ip + click.type)
			
			if not history:
				history = TallstreetHistory.get_or_insert(key_name="history%s%s" % (keyword.key(), url.key()))
				history.universe = universe
				history.changes.insert(0, long(change))
				history.dates.insert(0, date)
			elif history.universe != universe or history.dates[0] != date:			
				logging.debug("Adding history %s %s %s" % (ips, history.changes[0], history.dates[0]))
				historychanges = TallstreetHistoryChanges.get_or_insert(history.key().id_or_name())
				historychanges.ips = ips
				historychanges.put()
				history.put()
				ips = []
				history = TallstreetHistory.get_or_insert(key_name="history%s%s" % (keyword.key(), url.key()))
				history.changes.insert(0, long(change))
				history.dates.insert(0, date)
				history.universe = universe
			else:					
				logging.debug("Add Change %s" % (change))
				history.changes[0] += long(change)
				
				
		
		if history:
			logging.debug("Adding history %s %s %s" % (ips, history.changes[0], history.dates[0]))
			historychanges = TallstreetHistoryChanges.get_or_insert(history.key().id_or_name())
			historychanges.ips = ips
			historychanges.put()
			history.put()	
		return []
Ejemplo n.º 7
0
	def get_object(self, category):
		category = category[0].replace("_", " ")
		tagdata = TallstreetTags.get(category)
		if not tagdata:
				raise FeedDoesNotExist
		return tagdata