def wordcloud(request): eStats = EvernoteStatistics(request.user.profile) t = eStats.get_first_note_timestamp() notebooks = eStats.get_guid_map(notebookNames=True, tagNames=False).items() tags = eStats.get_guid_map(notebookNames=False, tagNames=True).items() return render_to_response('wordcloud.html', {'firstNote': t, 'EVERNOTE_HOST': settings.EVERNOTE_HOST, 'notebooks': notebooks, 'tags': tags}, context_instance=RequestContext(request))
def geo_loc_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) noteMetadata = eStats.get_note_metadata(filt) if noteMetadata is None: return HttpResponse({},content_type='application/json') jsonText = json.dumps({'points' : noteMetadata['geoLocations']}) return HttpResponse(jsonText,content_type='application/json')
def trends(request): eStats = EvernoteStatistics(request.user.profile) try: t = eStats.get_first_note_timestamp() #If we get an error while looking up a user's data send back to login except evernoteError.EDAMUserException: logout(request) return HttpResponseRedirect(reverse('account.views.login_page', args=[])) notebooks = eStats.get_guid_map(notebookNames=True, tagNames=False).items() tags = eStats.get_guid_map(notebookNames=False, tagNames=True).items() return render_to_response('trends.html', {'firstNote': t, 'notebooks': notebooks, 'tags': tags}, context_instance=RequestContext(request))
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')
def notebook_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) qStats = eStats.get_quick_stats(filt) if qStats is None: return HttpResponse({},content_type='application/json') guidToNameMap = eStats.get_guid_map(notebookNames=True) noteFrequency = qStats['notebookCounts'] notebookArray = [[k,v] for k,v in noteFrequency.iteritems()] jsonText = json.dumps({'keyToDisplayMap': guidToNameMap, 'noteArray': notebookArray, 'displayObjectName': 'Notebook', 'evernoteSearchParam' : 'b'}) return HttpResponse(jsonText,content_type='application/json')
def day_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) noteMetadata = eStats.get_note_metadata(filt) if noteMetadata is None: return HttpResponse({},content_type='application/json') dayFrequency = noteMetadata['dayCounter'] intToDayMap = {0: "Sunday", 1: "Monday", 2: "Tuesday", 3: "Wednesday", 4: "Thursday", 5: "Friday", 6: "Saturday"} daysArray = [[x,0] for x in intToDayMap.values()] for (k,v) in dayFrequency.iteritems(): daysArray[k][1] = v jsonText = json.dumps({'categoryCounts': daysArray, 'categoryTitle': 'Day'}) return HttpResponse(jsonText,content_type='application/json')
def post_evernote_token(request): """ View that is called after a user has sucessfully received a token and displays information """ eStats = EvernoteStatistics(request.user.profile) # qStats = eStats.get_quick_stats() qStats = eStats.get_quick_stats_created_recently(month=12) if qStats is None: return render_to_response('evernote_resp.html', {'numNotebooks' : "No notebooks found for the given time period", 'notebooks' : "", 'notes': "", 'tags': "", 'days': ""}, context_instance=RequestContext(request)) numNotebooks = "Found " + str(qStats['numberOfNotebooks']) + " notebooks:" notebookFrequency = qStats['notebookCounts'] tagFrequency = qStats['tagCounts'] notes = "Found " + str(qStats['numberOfNotes']) + " notes" notebooks = "Found " + str(qStats['numberOfNotebooks']) + " notebooks:" tags = "Found " + str(qStats['numberOfTags']) + " tags: " for (notebook, frequency) in notebookFrequency.items(): notebooks += eStats.get_notebook_name(notebook) + ": " + str(frequency) + " * " for (tag, frequency) in tagFrequency.items(): tags += eStats.get_tag_name(tag) + ": " + str(frequency) + " * " dayFrequency = eStats.get_note_creation() days = "Number of notes created on the following days: " for (day, frequency) in dayFrequency.items(): days += str(day) + ": " + str(frequency) + " * " return render_to_response('evernote_resp.html', {'numNotebooks' : numNotebooks, 'notebooks' : notebooks, 'notes' : notes, 'tags' : tags, 'days' : days}, context_instance=RequestContext(request))
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')
def month_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) noteMetadata = eStats.get_note_metadata(filt) if noteMetadata is None: return HttpResponse({},content_type='application/json') monthFrequency = noteMetadata['monthCounter'] intToMonthMap = {1: "January", 2: "February", 3: "March", 4: "April", 5: "May", 6: "June", 7: "July", 8: "August", 9: "September", 10: "October", 11: "November", 12: "December"} monthsArray = [[x,0] for x in intToMonthMap.values()] for (k,v) in monthFrequency.iteritems(): monthsArray[k-1][1] = v jsonText = json.dumps({'categoryCounts': monthsArray, 'categoryTitle': 'Month'}) return HttpResponse(jsonText,content_type='application/json')
def word_update(request): if request.method == 'GET': eStats = EvernoteStatistics(request.user.profile) eStats.update_word_count() return HttpResponse("",content_type='application/json')
def map(request): eStats = EvernoteStatistics(request.user.profile) t = eStats.get_first_note_timestamp() return render_to_response('map.html', {'firstNote': t}, context_instance=RequestContext(request))
def organization(request): eStats = EvernoteStatistics(request.user.profile) t = eStats.get_first_note_timestamp() return render_to_response('organization.html', {'firstNote': t, 'EVERNOTE_HOST': settings.EVERNOTE_HOST}, context_instance=RequestContext(request))