def store_incomplete_hash_info(user, rawTimelineData, t): """ Save data on bit.ly hashes to MySQL db. """ from django.db import models from models import ModelInputs # Do any hashes exist in the SQL db? If so, update the db instead of adding # a new row. Consider moving this logic to tstatus2.py (to avoid looping # over rawTimelineData multiple times). if t != None: for h in rawTimelineData.keys(): try: query = ModelInputs.objects.get(username = user, bhash = h) query.clicks = rawTimelineData[h]['clicks'] query.source = rawTimelineData[h]['source'] query.time = t query.save() except ModelInputs.DoesNotExist: x = ModelInputs(username = user, bhash = h, time = t, clicks = rawTimelineData[h]['clicks'], cpm = 0, cpd = 0, timeline_count = rawTimelineData[h]['timeline_count'], source = rawTimelineData[h]['source'], score = 0) x.save()
def store_new_hash_info(hashList, t): """ Commands to update MySQL tables with ALL data. Break these commands into their own functions soon. """ from django.db import models from models import HashData, BitlyHashInfo, ModelData for h in hashList: z = ModelInputs(username = user, bhash = h, time = t, clicks = hi5[h]['clicks'], cpm = hi5[h]['cpm'], cpd = hi5[h]['cpd'], timeline_count = hi5[h]['timeline_count'], source = hi5[h]['source'], score = hi5[h]['score']) z.save()
def store_hash_info(user, incompleteHashInfo, t): """ Save data on bit.ly hashes to MySQL db. """ from django.db import models from models import ModelInputs if t != None: for h in bitlyHashInfo.keys(): x = ModelInputs(username = user, bhash = h, time = t, clicks = bitlyHashInfo[h]['clicks'], cpm = bitlyHashInfo[h]['cpm'], cpd = bitlyHashInfo[h]['cpd'], timeline_count = bitlyHashInfo[h]['timeline_count'], source = bitlyHashInfo[h]['source'], score = bitlyHashInfo[h]['score']) x.save()