示例#1
0
def invest(request, url, new_keyword = ""):
	if not(re.search("^http", url)):
		url = "http://%s" % url
	

	payload = {}
	keywords = []
	payload["base_balance"] = request.user.money_outstanding
	payload["this_investment"] = 0
	if request.method == 'POST': 	
		if request.POST.has_key("sitename"):
			dburl = TallstreetUrls.get_or_insert("url%s" % url)
			dburl.title = request.POST["sitename"]
			dburl.description = request.POST["description"]
			dburl.url = url
			dburl.put()
		else:
			dburl = TallstreetUrls.get_url(url)	
		i = 0
		while True:
			if not(request.POST.has_key("investment[%s]" % i)):
				break
			investment = request.POST["investment[%s]" % i]
			keyword = request.POST["keyword[%s]" % i]
			if not(request.POST.has_key("edit[%s]" % i)):
				edit = True
			else:
				edit = request.POST["edit[%s]" % i]
			keywords.append({"keyword": keyword, "amount": investment, 'edit': edit})
			investment = investment.replace(".", "")
			investment = investment.replace(",", "")
			investment = investment.replace("$", "")
			#investment = investment.replace("¢", "")
			if investment == "":
				investment = 0
			else:
				investment = int(investment)
			payload["base_balance"] -= investment
			payload["this_investment"] += investment
			keyword = keyword.replace("_", " ")
			keyword = keyword.strip()
			if keyword == "" and investment > 0:
				payload["error"] = "You must enter a keyword"
				payload["errorrow"] = i
			elif keyword == "" and investment == 0:
				pass
			elif investment < 0:
				payload["error"] = "You must invest a positive amount"
				payload["errorrow"] = i			
			else:
				try:
					update_url(request.user, keyword, dburl, investment, request.META["REMOTE_ADDR"])
				except forms.ValidationError, error:
					payload["error"] = error.messages[0]
					payload["errorrow"] = i
			i += 1
		if not(payload.has_key("error")):
			return HttpResponseRedirect('/portfolio') 
示例#2
0
def get_referrer(request):
	parsed = urlparse.urlparse(request.META["HTTP_REFERER"])
	if parsed[1].find(request.META["SERVER_NAME"]) == -1:
		url = TallstreetUrls.get_url(request.META["HTTP_REFERER"])
		if not(url):
			domain = urlparse.urlunparse((parsed[0], parsed[1], '', '', '', ''))
			url = TallstreetUrls.get_url(domain)	
		return url
	return False	
示例#3
0
def url(request, url):
	payload = {}
	payload["url"] = TallstreetUrls.get_url(url)
	if not payload["url"]:
		return HttpResponseNotFound('<h1>Url not added</h1><p>Click <a href="http://www.tallstreet.com/invest/%s">http://www.tallstreet.com/invest/%s</a> to add it.' % (url, url)) 
	payload["otherurls"] = payload["url"].get_other_urls()		
	return render(request, 'url.html', payload)

	    
示例#4
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")
示例#5
0
  def HandleEntity(self, entity):
	url = TallstreetUrls()
	url.url = entity["url"]
	url.title = entity["title"]
	if entity.has_key("description"):
		url.description = entity["description"]
	else:
		url.description = ""
	newent = datastore.Entity('TallstreetUrls', name="url%s" % (entity['url']))	
	url._to_entity(newent)	
	return newent
示例#6
0
				pass
			elif investment < 0:
				payload["error"] = "You must invest a positive amount"
				payload["errorrow"] = i			
			else:
				try:
					update_url(request.user, keyword, dburl, investment, request.META["REMOTE_ADDR"])
				except forms.ValidationError, error:
					payload["error"] = error.messages[0]
					payload["errorrow"] = i
			i += 1
		if not(payload.has_key("error")):
			return HttpResponseRedirect('/portfolio') 
			
	payload["tags"] = {}
	dburl = TallstreetUrls.get_url(url)	

	if not(dburl):
		dburl = TallstreetUrls.get_url(url[0:-1])	
		if dburl:
			url = url[0:-1]
	if dburl:
		payload["url"] = dburl.url
		payload["title"] = dburl.title 
		payload["description"] = dburl.description
		payload["new"] = False
			
		for keyword in dburl.related_keywords:
			payload["tags"][keyword.tag.tag] = min(keyword.money / 1000 + 10, 30)
	else:
		page = fetch(url)
示例#7
0
文件: feeds.py 项目: stall/tallstreet
	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 []