Example #1
0
def trends_json(request):
   if request.method == 'GET':
      GET = request.GET
      if GET.has_key('sDate') and GET.has_key('eDate'):
         eStats = EvernoteStatistics(request.user.profile)
         startDate = date.fromtimestamp(float(GET['sDate'])/1000)
         endDate = date.fromtimestamp(float(GET['eDate'])/1000)
         filt = eStats.create_date_filter(startDate, endDate)
         if GET.has_key('tag'):
            filt = eStats.create_guid_filter(GET['tag'],False,filt)    
         if GET.has_key('notebook'):
            filt = eStats.create_guid_filter(GET['notebook'],True,filt)    
         #if the time frame is across multiple years then use months
         formattedTrend = [["Date","Notes"]]
         if (endDate.year - startDate.year) > 1:
            dateTrends = eStats.get_date_trends(True,filt)
            for dt in rrule.rrule(rrule.MONTHLY, dtstart=startDate, 
                                                 until=endDate):
               formattedTrend.append([dt.strftime("%b \'%y"),
                                     dateTrends[dt.strftime("%b \'%y")]])
         else:
            dateTrends = eStats.get_date_trends(False,filt)
            for dt in rrule.rrule(rrule.DAILY, dtstart=startDate, 
                                               until=endDate):
               formattedTrend.append([dt.strftime("%d %b"),
                                     dateTrends[dt.strftime("%d %b")]])
         jsonText = json.dumps({'data': formattedTrend,
                                'title': "Total Notes"})
         return HttpResponse(jsonText,content_type='application/json')
Example #2
0
def word_count_json(request):
    if request.method == 'GET':
      GET = request.GET
      if GET.has_key('sDate') and GET.has_key('eDate'):
         eStats = EvernoteStatistics(request.user.profile)
         startDate = date.fromtimestamp(float(GET['sDate'])/1000)
         endDate = date.fromtimestamp(float(GET['eDate'])/1000)
         filt = eStats.create_date_filter(startDate, endDate)
         if GET.has_key('tag'):
            filt = eStats.create_guid_filter(GET['tag'],False,filt)    
         if GET.has_key('notebook'):
            filt = eStats.create_guid_filter(GET['notebook'],True,filt)    
         wordCount = eStats.get_word_count(filt, numWords=200)
         #what happens when no data?
         jsonText = json.dumps({'words' : wordCount})
         return HttpResponse(jsonText,content_type='application/json')