Skip to content

Instantly share code, notes, and snippets.

@ovnicraft
Forked from name1984/gist:9552608e8b3630660dfa
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ovnicraft/1639a33651c07b320d33 to your computer and use it in GitHub Desktop.
Save ovnicraft/1639a33651c07b320d33 to your computer and use it in GitHub Desktop.
__author__ = 'name1984'
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import MySQLdb
import json
import csv
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
bd = MySQLdb.connect('localhost','edxapp001','password','edxapp')
# Preparamos el cursor que nos va a ayudar a realizar las operaciones con la base de datos
cursor = bd.cursor()
# Ejecutamos un query SQL usando el metodo execute() que nos proporciona el cursor
cursor.execute(""
" select "
" courseware_offlinecomputedgrade.gradeset, auth_userprofile.name, auth_userprofile.cedula "
" from "
" courseware_offlinecomputedgrade "
"inner join "
" auth_userprofile "
"WHERE "
" courseware_offlinecomputedgrade.user_id = auth_userprofile.user_id "
" and courseware_offlinecomputedgrade.course_id = 'course-v1:mineduc-forma+LMN101+2015_07'")
data = cursor.fetchall()
rowarray_list = []
aux = {}
for item in data:
dic = json.loads(item[0])
aux = {'nombres-apellidos': item[1], 'cedula':item[2]}
dic.update(aux)
rowarray_list.append(dic)
preguntas_list = []
preg_tab_list = {}
i = 0
with open('grade_report.csv', 'w') as csvfile:
i = 0
for dic in rowarray_list:
if dic.has_key('section_breakdown'):
print "-----------------------------------"
print "Participante : %s Cedula : %s" %(dic['nombres-apellidos'], dic['cedula'])
fieldnames = ['nombres apellidos', 'cedula', 'grades', j.values()[0] for j in dic['section_breakdown']]
if i == 0:
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
i = i + 1
for test in dic['section_breakdown']:
writer.writerow({'nombres apellidos': dic['nombres-apellidos'], 'cedula': dic['cedula'], i.values() for i in test})
print u"%s"%test['detail']
bd.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment