예제 #1
0
def export_json(request, selected_attributes):
	studyid =  request.session['study_select']
	tweet_resource = resources.create_TweetResource(get_attributes_to_export(selected_attributes))
	dataset = tweet_resource.export(Study.objects.get(study_id=studyid).tweets.all())
	response = HttpResponse(dataset.json, content_type='application/json')
	response['Content-Disposition'] = 'attachment; filename="'+ studyid + ' - '  + str(datetime.now()) +'.json"'
	return response
예제 #2
0
def export_xml(request, selected_attributes):
	studyid =  request.session['study_select']
	tweet_resource = resources.create_TweetResource(get_attributes_to_export(selected_attributes))
	dataset = tweet_resource.export(Study.objects.get(study_id=studyid).tweets.all())
	obj = json.loads(dataset.json)
	xml = dicttoxml.dicttoxml(obj)
	xml_pretty = parseString(xml).toprettyxml()
	response = HttpResponse(xml_pretty, content_type='text/xml')
	response['Content-Disposition'] = 'attachment; filename="'+ studyid + ' - '  + str(datetime.now()) +'.xml"'
	return response
예제 #3
0
def export_spss(request, selected_attributes):
	studyid =  request.session['study_select']
	tweet_resource = resources.create_TweetResource(get_attributes_to_export(selected_attributes))
	dataset = tweet_resource.export(Study.objects.get(study_id=studyid).tweets.all())
	obj = json.loads(dataset.json)
	df = pd.json_normalize(obj)
	pyreadstat.write_sav(df, 'Data/SPSS/template.sav')
	response = HttpResponse()
	f = default_storage.open('Data/SPSS/template.sav').read()
	# response.write(f)
	response = HttpResponse(f, content_type='application/x-spss-sav')
	response['Content-Disposition'] = 'attachment; filename="'+ studyid + ' - '  + str(datetime.now()) +'.sav"'
	return response