diff --git a/lib/json_group_section.py b/lib/json_group_section.py index f0bb2b8eeb855897ed23267e6f24176cbf086864..8593519b4a05e30cae4c798f22b65cd029343619 100644 --- a/lib/json_group_section.py +++ b/lib/json_group_section.py @@ -24,6 +24,7 @@ import MySQLdb import queries_definition as qry +import string_functions as strf import json_support_functions as wrt ###################################################################### @@ -48,7 +49,7 @@ def write_groupmembers_subsection (db, json, group_guid): wrt.write_open_tag(json,3,"","{") prefix='profile/' - user_attr=wrt.urlparticipa(prefix,user_username) + user_attr=strf.urlparticipa(prefix,user_username) wrt.write_open_tag(json,4,"usuario","{") wrt.write_tag(json,5,"uid",user_attr,",") @@ -85,14 +86,14 @@ def write_groupfiles_subsection (db, json, group_guid): wrt.write_open_tag(json,3,"","{") prefix='file/download/' - file_link=wrt.urlparticipa(prefix,str(post_guid)) + file_link=strf.urlparticipa(prefix,str(post_guid)) prefix='file/view/' - post_attr=wrt.urlparticipa(prefix,str(post_guid)) + post_attr=strf.urlparticipa(prefix,str(post_guid)) wrt.write_tag(json,4,"pid",post_attr,",") prefix='profile/' - owner_attr=wrt.urlparticipa(prefix,owner_username) + owner_attr=strf.urlparticipa(prefix,owner_username) wrt.write_open_tag(json,4,"autor","{") wrt.write_tag(json,5,"uid",owner_attr,",") @@ -100,7 +101,7 @@ def write_groupfiles_subsection (db, json, group_guid): wrt.write_close_tag(json,4,"}",True) wrt.write_tag(json,4,"titulo",post_title,",") - wrt.write_tag(json,4,"data",wrt.datestr(time),",") + wrt.write_tag(json,4,"data",strf.datestr(time),",") wrt.write_tag(json,4,"link",file_link,",") wrt.write_tag(json,4,"descricao",post_desc,",") @@ -136,11 +137,11 @@ def write_groupforumtopics_subsection (db, json, group_guid): wrt.write_open_tag(json,3,"","{") prefix='discussion/view/' - post_attr=wrt.urlparticipa(prefix,str(post_guid)) + post_attr=strf.urlparticipa(prefix,str(post_guid)) wrt.write_tag(json,4,"pid",post_attr,",") prefix='profile/' - owner_attr=wrt.urlparticipa(prefix,owner_username) + owner_attr=strf.urlparticipa(prefix,owner_username) wrt.write_open_tag(json,4,"autor","{") wrt.write_tag(json,5,"uid",owner_attr,",") @@ -148,7 +149,7 @@ def write_groupforumtopics_subsection (db, json, group_guid): wrt.write_close_tag(json,4,"}",True) wrt.write_tag(json,4,"titulo",post_title,",") - wrt.write_tag(json,4,"data",wrt.datestr(time),",") + wrt.write_tag(json,4,"data",strf.datestr(time),",") wrt.write_tag(json,4,"texto",post_desc,",") wrt.write_comments(db,json,post_guid) @@ -186,11 +187,11 @@ def write_groupbookmarks_subsection (db, json, group_guid): bookmark_link=qry.post_content(db,post_guid,90) prefix='bookmarks/view/' - post_attr=wrt.urlparticipa(prefix,str(post_guid)) + post_attr=strf.urlparticipa(prefix,str(post_guid)) wrt.write_tag(json,4,"pid",post_attr,",") prefix='profile/' - owner_attr=wrt.urlparticipa(prefix,owner_username) + owner_attr=strf.urlparticipa(prefix,owner_username) wrt.write_open_tag(json,4,"autor","{") wrt.write_tag(json,5,"uid",owner_attr,",") @@ -198,7 +199,7 @@ def write_groupbookmarks_subsection (db, json, group_guid): wrt.write_close_tag(json,4,"}",True) wrt.write_tag(json,4,"titulo",post_title,",") - wrt.write_tag(json,4,"data",wrt.datestr(time),",") + wrt.write_tag(json,4,"data",strf.datestr(time),",") wrt.write_tag(json,4,"link",bookmark_link,",") wrt.write_tag(json,4,"descricao",post_desc,",") @@ -234,11 +235,11 @@ def write_grouppages_subsection (db, json, group_guid): wrt.write_open_tag(json,3,"","{") prefix='pages/view/' - post_attr=wrt.urlparticipa(prefix,str(post_guid)) + post_attr=strf.urlparticipa(prefix,str(post_guid)) wrt.write_tag(json,4,"pid",post_attr,",") prefix='profile/' - owner_attr=wrt.urlparticipa(prefix,owner_username) + owner_attr=strf.urlparticipa(prefix,owner_username) wrt.write_open_tag(json,4,"autor","{") wrt.write_tag(json,5,"uid",owner_attr,",") @@ -246,7 +247,7 @@ def write_grouppages_subsection (db, json, group_guid): wrt.write_close_tag(json,4,"}",True) wrt.write_tag(json,4,"titulo",post_title,",") - wrt.write_tag(json,4,"data",wrt.datestr(time),",") + wrt.write_tag(json,4,"data",strf.datestr(time),",") wrt.write_tag(json,4,"texto",post_desc,",") wrt.write_comments(db,json,post_guid) @@ -284,11 +285,11 @@ def write_groupvideos_subsection (db, json, group_guid): wrt.write_open_tag(json,3,"","{") prefix='videos/view/' - post_attr=wrt.urlparticipa(prefix,str(post_guid)) + post_attr=strf.urlparticipa(prefix,str(post_guid)) wrt.write_tag(json,4,"pid",post_attr,",") prefix='profile/' - owner_attr=wrt.urlparticipa(prefix,owner_username) + owner_attr=strf.urlparticipa(prefix,owner_username) wrt.write_open_tag(json,4,"autor","{") wrt.write_tag(json,5,"uid",owner_attr,",") @@ -296,7 +297,7 @@ def write_groupvideos_subsection (db, json, group_guid): wrt.write_close_tag(json,4,"}",True) wrt.write_tag(json,4,"titulo",post_title,",") - wrt.write_tag(json,4,"data",wrt.datestr(time),",") + wrt.write_tag(json,4,"data",strf.datestr(time),",") wrt.write_tag(json,4,"link",video_link,",") wrt.write_tag(json,4,"descricao",post_desc,",") @@ -350,11 +351,11 @@ def write_groupevents_subsection (db, json, group_guid): organizer=qry.post_content(db, post_guid, 30) prefix='event_calendar/view/' - post_attr=wrt.urlparticipa(prefix,str(post_guid)) + post_attr=strf.urlparticipa(prefix,str(post_guid)) wrt.write_tag(json,4,"pid",post_attr,",") prefix='profile/' - owner_attr=wrt.urlparticipa(prefix,owner_username) + owner_attr=strf.urlparticipa(prefix,owner_username) wrt.write_open_tag(json,4,"autor","{") wrt.write_tag(json,5,"uid",owner_attr,",") @@ -362,12 +363,12 @@ def write_groupevents_subsection (db, json, group_guid): wrt.write_close_tag(json,4,"}",True) wrt.write_tag(json,4,"titulo",post_title,",") - wrt.write_tag(json,4,"data",wrt.datestr(time),",") + wrt.write_tag(json,4,"data",strf.datestr(time),",") wrt.write_tag(json,4,"organizador",organizer,",") wrt.write_tag(json,4,"contato",contact,",") wrt.write_tag(json,4,"endereco",venue,",") - wrt.write_tag(json,4,"dataInicio",wrt.datestr(time_start),",") - wrt.write_tag(json,4,"dataFim",wrt.datestr(time_end),",") + wrt.write_tag(json,4,"dataInicio",strf.datestr(time_start),",") + wrt.write_tag(json,4,"dataFim",strf.datestr(time_end),",") wrt.write_tag(json,4,"taxaParticipacao",fees,",") wrt.write_tag(json,4,"descricao",post_desc,",") @@ -388,12 +389,12 @@ def write_groups_section (db, json,\ brief_desc=qry.post_content(db,guid, 45) prefix='groups/profile/' - group_attr=wrt.urlparticipa(prefix,str(guid)) + group_attr=strf.urlparticipa(prefix,str(guid)) wrt.write_tag(json,2,"cid",group_attr,",") # Write all group's information prefix='profile/' - owner_attr=wrt.urlparticipa(prefix,owner_username) + owner_attr=strf.urlparticipa(prefix,owner_username) wrt.write_open_tag(json,2,"proprietario","{") wrt.write_tag(json,3,"uid",owner_attr,",") @@ -401,7 +402,7 @@ def write_groups_section (db, json,\ wrt.write_close_tag(json,2,"}",True) wrt.write_tag(json,2,"titulo",title,",") - wrt.write_tag(json,2,"data",wrt.datestr(time),",") + wrt.write_tag(json,2,"data",strf.datestr(time),",") wrt.write_tag(json,2,"descricao",desc,",") group_access = qry.groupaccess_permission(db, guid) @@ -433,7 +434,7 @@ def write_singlefile_groups_section (db, dir_results): groups_info = db.cursor() groups_info.execute(qry.qry_groups_info) - json_filename=dir_results+wrt.date_today()+"_comunidades"+".json" + json_filename=dir_results+strf.date_today()+"_comunidades"+".json" json = wrt.open_json_file(json_filename) wrt.write_open_tag(json,0,"","{") diff --git a/lib/json_support_functions.py b/lib/json_support_functions.py index 88e416cc045b05073b20d1de2cb79e8be2f6d966..01a2ee21cd35a09da19b6db8739e249c30bed449 100644 --- a/lib/json_support_functions.py +++ b/lib/json_support_functions.py @@ -26,6 +26,7 @@ import codecs import datetime import base64 +import string_functions as strf import queries_definition as qry ###################################################################### @@ -37,79 +38,27 @@ def open_json_file (json_filename): return json_file #--------------------------------------------------------------------# -#--------------------------------------------------------------------# -def date_today(): - date = str(datetime.date.today()) - return date -#--------------------------------------------------------------------# - -#--------------------------------------------------------------------# -def lvl (l): - if l == 1: - return "\t" - elif l == 2: - return "\t\t" - elif l == 3: - return "\t\t\t" - elif l == 4: - return "\t\t\t\t" - elif l == 5: - return "\t\t\t\t\t" - elif l == 6: - return "\t\t\t\t\t\t" - elif l == 7: - return "\t\t\t\t\t\t\t" - else: - return "" -#--------------------------------------------------------------------# - -#--------------------------------------------------------------------# -def substbadc (string): - string = string.replace('\\','\\\\') - string = string.replace('"','\\"') - string = string.replace('\t',' ') - string = string.replace('\n',' ') - string = string.replace('\r',' ') - return string -#--------------------------------------------------------------------# - -#--------------------------------------------------------------------# -def urlparticipa (prefix, guid): - http_str="http://participatorio.juventude.gov.br/" - url_participa=http_str+prefix+guid - return url_participa -#--------------------------------------------------------------------# - -#--------------------------------------------------------------------# -def datestr (time): - if time != '': - date=str(datetime.datetime.fromtimestamp(int(time))) - else: - date='' - return date -#--------------------------------------------------------------------# - #--------------------------------------------------------------------# def write_open_tag (xml, l, tag_name, sep): if len(tag_name) > 0: - xml.write(lvl(l)+"\""+tag_name+"\""+":"+sep+"\n") + xml.write(strf.lvl(l)+"\""+tag_name+"\""+":"+sep+"\n") else: - xml.write(lvl(l)+sep+"\n") + xml.write(strf.lvl(l)+sep+"\n") #--------------------------------------------------------------------# #--------------------------------------------------------------------# def write_close_tag (xml, l, sep, comma_flag): if comma_flag == True: - xml.write(lvl(l)+sep+","+"\n") + xml.write(strf.lvl(l)+sep+","+"\n") else: - xml.write(lvl(l)+sep+"\n") + xml.write(strf.lvl(l)+sep+"\n") #--------------------------------------------------------------------# #--------------------------------------------------------------------# def write_tag (xml, l, tag_name, info_str, comma): name="\""+tag_name+"\"" - info="\""+substbadc(info_str)+"\"" - xml.write(lvl(l)+name+":"+info+comma+"\n") + info="\""+strf.substbadc(info_str)+"\"" + xml.write(strf.lvl(l)+name+":"+info+comma+"\n") #--------------------------------------------------------------------# #--------------------------------------------------------------------# @@ -128,14 +77,14 @@ def write_comments (db, xml, post_guid): write_open_tag(xml,5,"","{") prefix='profile/' - user_attr=urlparticipa(prefix,user_username) + user_attr=strf.urlparticipa(prefix,user_username) write_open_tag(xml,6,"usuario","{") write_tag(xml,7,"uid",user_attr,",") write_tag(xml,7,"nome",user_name,"") write_close_tag(xml,6,"}",True) - write_tag(xml,6,"data",datestr(time),",") + write_tag(xml,6,"data",strf.datestr(time),",") write_tag(xml,6,"mensagem",string,"") write_close_tag(xml,5,"}",(row < post_comments.rowcount)) diff --git a/lib/json_user_section.py b/lib/json_user_section.py index 716176ee95da456122095e453a31f24650dfa957..3e25fcddecc912ceebb8c88509c45e66b83489a2 100644 --- a/lib/json_user_section.py +++ b/lib/json_user_section.py @@ -24,6 +24,7 @@ import MySQLdb import queries_definition as qry +import string_functions as strf import json_support_functions as wrt ###################################################################### @@ -48,7 +49,7 @@ def write_userfriends_subsection (db, json, user_guid): wrt.write_open_tag(json,3,"","{") prefix='profile/' - friend_attr=wrt.urlparticipa(prefix,friend_username) + friend_attr=strf.urlparticipa(prefix,friend_username) wrt.write_tag(json,4,"uid",friend_attr,",") wrt.write_tag(json,4,"usuario",friend_name,"") @@ -76,7 +77,7 @@ def write_userowngroup_subsection (db, json, user_guid): wrt.write_open_tag(json,4,"","{") prefix='groups/profile/' - group_attr=wrt.urlparticipa(prefix,str(group_id)) + group_attr=strf.urlparticipa(prefix,str(group_id)) wrt.write_tag(json,5,"cid",group_attr,",") wrt.write_tag(json,5,"titulo",group_title,"") @@ -104,7 +105,7 @@ def write_usermembergroup_subsection (db, json, user_guid): wrt.write_open_tag(json,4,"","{") prefix='groups/profile/' - group_attr=wrt.urlparticipa(prefix,str(group_id)) + group_attr=strf.urlparticipa(prefix,str(group_id)) wrt.write_tag(json,5,"cid",group_attr,",") wrt.write_tag(json,5,"titulo",group_title,"") @@ -140,16 +141,16 @@ def write_userfiles_subsection (db, json, user_guid): row=row+1 prefix="file/download/" - file_link=wrt.urlparticipa(prefix,str(post_guid)) + file_link=strf.urlparticipa(prefix,str(post_guid)) prefix='file/view/' - post_attr=wrt.urlparticipa(prefix,str(post_guid)) + post_attr=strf.urlparticipa(prefix,str(post_guid)) wrt.write_open_tag(json,3,"","{") wrt.write_tag(json,4,"pid",post_attr,",") wrt.write_tag(json,4,"titulo",post_title,",") - wrt.write_tag(json,4,"data",wrt.datestr(time),",") + wrt.write_tag(json,4,"data",strf.datestr(time),",") wrt.write_tag(json,4,"link",file_link,",") wrt.write_tag(json,4,"descricao",post_desc,",") @@ -183,12 +184,12 @@ def write_userblogs_subsection (db, json, user_guid): post_excerpt=qry.post_content(db,post_guid,64) prefix='blog/view/' - post_attr=wrt.urlparticipa(prefix,str(post_guid)) + post_attr=strf.urlparticipa(prefix,str(post_guid)) wrt.write_open_tag(json,3,"","{") wrt.write_tag(json,4,"pid",post_attr,",") wrt.write_tag(json,4,"titulo",post_title,",") - wrt.write_tag(json,4,"data",wrt.datestr(time),",") + wrt.write_tag(json,4,"data",strf.datestr(time),",") wrt.write_tag(json,4,"resumo",post_excerpt,",") wrt.write_tag(json,4,"texto",post_desc,",") @@ -220,12 +221,12 @@ def write_userbookmarks_subsection (db, json, user_guid): bookmark_link=qry.post_content(db,post_guid,90) prefix='bookmarks/view/' - post_attr=wrt.urlparticipa(prefix,str(post_guid)) + post_attr=strf.urlparticipa(prefix,str(post_guid)) wrt.write_open_tag(json,3,"","{") wrt.write_tag(json,4,"pid",post_attr,",") wrt.write_tag(json,4,"titulo",post_title,",") - wrt.write_tag(json,4,"data",wrt.datestr(time),",") + wrt.write_tag(json,4,"data",strf.datestr(time),",") wrt.write_tag(json,4,"link",bookmark_link,",") wrt.write_tag(json,4,"descricao",post_desc,",") @@ -254,13 +255,13 @@ def write_userpages_subsection (db, json, user_guid): row=row+1 prefix='pages/view/' - post_attr=wrt.urlparticipa(prefix,str(post_guid)) + post_attr=strf.urlparticipa(prefix,str(post_guid)) wrt.write_open_tag(json,3,"","{") wrt.write_tag(json,4,"pid",post_attr,",") wrt.write_tag(json,4,"titulo",post_title,",") - wrt.write_tag(json,4,"data",wrt.datestr(time),",") + wrt.write_tag(json,4,"data",strf.datestr(time),",") wrt.write_tag(json,4,"texto",post_desc,",") wrt.write_comments(db,json,post_guid) @@ -291,13 +292,13 @@ def write_uservideos_subsection (db, json, user_guid): video_link=qry.post_content(db, post_guid, 477) prefix='videos/view/' - post_attr=wrt.urlparticipa(prefix,str(post_guid)) + post_attr=strf.urlparticipa(prefix,str(post_guid)) wrt.write_open_tag(json,3,"","{") wrt.write_tag(json,4,"pid",post_attr,",") wrt.write_tag(json,4,"titulo",post_title,",") - wrt.write_tag(json,4,"data",wrt.datestr(time),",") + wrt.write_tag(json,4,"data",strf.datestr(time),",") wrt.write_tag(json,4,"link",video_link,",") wrt.write_tag(json,4,"descricao",post_desc,",") @@ -345,13 +346,13 @@ def write_userevents_subsection (db, json, user_guid): organizer=qry.post_content(db, post_guid, 30) prefix='event_calendar/view/' - post_attr=wrt.urlparticipa(prefix,str(post_guid)) + post_attr=strf.urlparticipa(prefix,str(post_guid)) wrt.write_open_tag(json,3,"","{") wrt.write_tag(json,4,"pid",post_attr,",") wrt.write_tag(json,4,"titulo",post_title,",") - wrt.write_tag(json,4,"data",wrt.datestr(time),",") + wrt.write_tag(json,4,"data",strf.datestr(time),",") wrt.write_tag(json,4,"organizador",organizer,",") wrt.write_tag(json,4,"contato",contact,",") wrt.write_tag(json,4,"endereco",venue,",") @@ -374,7 +375,7 @@ def write_users_section (db, json, \ guid, name, username): prefix='profile/' - user_attr=wrt.urlparticipa(prefix,username) + user_attr=strf.urlparticipa(prefix,username) # Write all user's information wrt.write_tag(json,2,"uid",user_attr,",") @@ -401,9 +402,7 @@ def write_singlefile_users_section (db, dir_results): users_info = db.cursor() users_info.execute(qry.qry_users_info) - return - - json_filename=dir_results+wrt.date_today()+"_usuarios"+".json" + json_filename=dir_results+strf.date_today()+"_usuarios"+".json" json = wrt.open_json_file(json_filename) wrt.write_open_tag(json,0,"","{") diff --git a/lib/string_functions.py b/lib/string_functions.py new file mode 100644 index 0000000000000000000000000000000000000000..0c4e292ad249caafa844778f9667535aa3d66506 --- /dev/null +++ b/lib/string_functions.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2004-2008 Centro de Computacao Cientifica e Software Livre +# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR +# +# This file is part of participatorio/opendata +# +# participatorio/opendata is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +# USA. + +import codecs +import datetime + +#--------------------------------------------------------------------# +def lvl (l): + if l == 1: + return "\t" + elif l == 2: + return "\t\t" + elif l == 3: + return "\t\t\t" + elif l == 4: + return "\t\t\t\t" + elif l == 5: + return "\t\t\t\t\t" + elif l == 6: + return "\t\t\t\t\t\t" + elif l == 7: + return "\t\t\t\t\t\t\t" + else: + return "" +#--------------------------------------------------------------------# + +#--------------------------------------------------------------------# +def date_today(): + return str(datetime.date.today()) +#--------------------------------------------------------------------# + +#--------------------------------------------------------------------# +def datestr (time): + if time != "": + return str(datetime.datetime.fromtimestamp(int(time))) + else: + return "" +#--------------------------------------------------------------------# + +#--------------------------------------------------------------------# +def cdata (string): + if len(string) > 0: + return "<![CDATA["+string+"]]>" + else: + return "" +#--------------------------------------------------------------------# + +#--------------------------------------------------------------------# +def uidstr (guid): + return " uid="+"\""+guid+"\"" +#--------------------------------------------------------------------# + +#--------------------------------------------------------------------# +def cidstr (guid): + return " cid="+"\""+guid+"\"" +#--------------------------------------------------------------------# + +#--------------------------------------------------------------------# +def pidstr (guid): + return " pid="+"\""+guid+"\"" +#--------------------------------------------------------------------# + +#--------------------------------------------------------------------# +def permstr (perm): + return " habilitado="+"\""+str(perm)+"\"" +#--------------------------------------------------------------------# + +#--------------------------------------------------------------------# +def qtystr (quantity): + return " quantidade="+"\""+str(quantity)+"\"" +#--------------------------------------------------------------------# + +#--------------------------------------------------------------------# +def urlparticipa (prefix, guid): + return "http://participatorio.juventude.gov.br/"+prefix+guid +#--------------------------------------------------------------------# + +#--------------------------------------------------------------------# +def hrefstr (url): + return " href="+"\""+url+"\"" +#--------------------------------------------------------------------# + +#--------------------------------------------------------------------# +def substbadc (string): + string = string.replace('\\','\\\\') + string = string.replace('"','\\"') + string = string.replace('\t',' ') + string = string.replace('\n',' ') + string = string.replace('\r',' ') + return string +#--------------------------------------------------------------------# diff --git a/lib/xml_group_section.py b/lib/xml_group_section.py index 3c800c3de6eb20041f620c08c43301476cf5cfd3..7bd8709bb7e493df9e8203e9d4c6609c437e3918 100644 --- a/lib/xml_group_section.py +++ b/lib/xml_group_section.py @@ -24,6 +24,7 @@ import MySQLdb import queries_definition as qry +import string_functions as strf import xml_support_functions as wrt ###################################################################### @@ -40,7 +41,7 @@ def write_groupmembers_subsection (db, xml, group_guid): wrt.write_open_tag(xml,2,"membros",'') for (user_id, user_name, user_username) in group_members: prefix='profile/' - user_attr=wrt.uidstr(wrt.urlparticipa(prefix,user_username)) + user_attr=strf.uidstr(strf.urlparticipa(prefix,user_username)) wrt.write_tag(xml,3,"usuario",user_name,user_attr) wrt.write_close_tag(xml,2,"membros") @@ -57,26 +58,26 @@ def write_groupfiles_subsection (db, xml, group_guid): # 50 = select * from elgg_metastrings where string='file_enable'; perm=qry.postcontent_permission(db, group_guid, 50) - wrt.write_open_tag(xml,2,"arquivos",wrt.permstr(perm)) + wrt.write_open_tag(xml,2,"arquivos",strf.permstr(perm)) for (post_guid, post_title, post_desc, \ owner_id, owner_name, owner_username, time)\ in group_files: prefix='file/download/' - file_link=wrt.urlparticipa(prefix,str(post_guid)) + file_link=strf.urlparticipa(prefix,str(post_guid)) prefix='file/view/' - post_attr=wrt.pidstr(wrt.urlparticipa(prefix,str(post_guid))) + post_attr=strf.pidstr(strf.urlparticipa(prefix,str(post_guid))) wrt.write_open_tag(xml,3,"arquivo",post_attr) prefix='profile/' - owner_attr=wrt.uidstr(wrt.urlparticipa(prefix,owner_username)) + owner_attr=strf.uidstr(strf.urlparticipa(prefix,owner_username)) wrt.write_tag(xml,4,"autor",owner_name,owner_attr) wrt.write_tag(xml,4,"titulo",post_title,'') - wrt.write_tag(xml,4,"data",wrt.datestr(time),'') - wrt.write_tag(xml,4,"link",'',wrt.hrefstr(file_link)) - wrt.write_tag(xml,4,"descricao",wrt.cdata(post_desc),'') + wrt.write_tag(xml,4,"data",strf.datestr(time),'') + wrt.write_tag(xml,4,"link",'',strf.hrefstr(file_link)) + wrt.write_tag(xml,4,"descricao",strf.cdata(post_desc),'') wrt.write_comments(db,xml,post_guid) @@ -97,22 +98,22 @@ def write_groupforumtopics_subsection (db, xml, group_guid): # 52 = select * from elgg_metastrings where string='forum_enable'; perm=qry.postcontent_permission(db, group_guid, 52) - wrt.write_open_tag(xml,2,"debates",wrt.permstr(perm)) + wrt.write_open_tag(xml,2,"debates",strf.permstr(perm)) for (post_guid, post_title, post_desc, \ owner_id, owner_name, owner_username, time)\ in group_forumtopics: prefix='discussion/view/' - post_attr=wrt.pidstr(wrt.urlparticipa(prefix,str(post_guid))) + post_attr=strf.pidstr(strf.urlparticipa(prefix,str(post_guid))) wrt.write_open_tag(xml,3,"debate",post_attr) prefix='profile/' - owner_attr=wrt.uidstr(wrt.urlparticipa(prefix,owner_username)) + owner_attr=strf.uidstr(strf.urlparticipa(prefix,owner_username)) wrt.write_tag(xml,4,"autor",owner_name,owner_attr) wrt.write_tag(xml,4,"titulo",post_title,'') - wrt.write_tag(xml,4,"data",wrt.datestr(time),'') - wrt.write_tag(xml,4,"texto",wrt.cdata(post_desc),'') + wrt.write_tag(xml,4,"data",strf.datestr(time),'') + wrt.write_tag(xml,4,"texto",strf.cdata(post_desc),'') wrt.write_comments(db,xml,post_guid) @@ -133,7 +134,7 @@ def write_groupbookmarks_subsection (db, xml, group_guid): # 49 = select * from elgg_metastrings where string='bookmarks_enable'; perm=qry.postcontent_permission(db, group_guid, 49) - wrt.write_open_tag(xml,2,"favoritos",wrt.permstr(perm)) + wrt.write_open_tag(xml,2,"favoritos",strf.permstr(perm)) for (post_guid, post_title, post_desc, \ owner_id, owner_name, owner_username, time)\ @@ -143,16 +144,16 @@ def write_groupbookmarks_subsection (db, xml, group_guid): bookmark_link=qry.post_content(db,post_guid,90) prefix='bookmarks/view/' - post_attr=wrt.pidstr(wrt.urlparticipa(prefix,str(post_guid))) + post_attr=strf.pidstr(strf.urlparticipa(prefix,str(post_guid))) wrt.write_open_tag(xml,3,"favorito",post_attr) prefix='profile/' - owner_attr=wrt.uidstr(wrt.urlparticipa(prefix,owner_username)) + owner_attr=strf.uidstr(strf.urlparticipa(prefix,owner_username)) wrt.write_tag(xml,4,"autor",owner_name,owner_attr) wrt.write_tag(xml,4,"titulo",post_title,'') - wrt.write_tag(xml,4,"data",wrt.datestr(time),'') - wrt.write_tag(xml,4,"link",'',wrt.hrefstr(bookmark_link)) - wrt.write_tag(xml,4,"descricao",wrt.cdata(post_desc),'') + wrt.write_tag(xml,4,"data",strf.datestr(time),'') + wrt.write_tag(xml,4,"link",'',strf.hrefstr(bookmark_link)) + wrt.write_tag(xml,4,"descricao",strf.cdata(post_desc),'') wrt.write_comments(db,xml,post_guid) @@ -173,22 +174,22 @@ def write_grouppages_subsection (db, xml, group_guid): # 53 = select * from elgg_metastrings where string='pages_enable'; perm=qry.postcontent_permission(db, group_guid, 53) - wrt.write_open_tag(xml,2,"paginas",wrt.permstr(perm)) + wrt.write_open_tag(xml,2,"paginas",strf.permstr(perm)) for (post_guid, post_title, post_desc, owner_id, owner_name, owner_username, time)\ in group_pages: prefix='pages/view/' - post_attr=wrt.pidstr(wrt.urlparticipa(prefix,str(post_guid))) + post_attr=strf.pidstr(strf.urlparticipa(prefix,str(post_guid))) wrt.write_open_tag(xml,3,"pagina",post_attr) prefix='profile/' - owner_attr=wrt.uidstr(wrt.urlparticipa(prefix,owner_username)) + owner_attr=strf.uidstr(strf.urlparticipa(prefix,owner_username)) wrt.write_tag(xml,4,"autor",owner_name,owner_attr) wrt.write_tag(xml,4,"titulo",post_title,'') - wrt.write_tag(xml,4,"data",wrt.datestr(time),'') - wrt.write_tag(xml,4,"texto",wrt.cdata(post_desc),'') + wrt.write_tag(xml,4,"data",strf.datestr(time),'') + wrt.write_tag(xml,4,"texto",strf.cdata(post_desc),'') wrt.write_comments(db,xml,post_guid) @@ -209,7 +210,7 @@ def write_groupvideos_subsection (db, xml, group_guid): # 399 = select * from elgg_metastrings where string='videos_enable'; perm=qry.postcontent_permission(db, group_guid, 399) - wrt.write_open_tag(xml,2,"videos",wrt.permstr(perm)) + wrt.write_open_tag(xml,2,"videos",strf.permstr(perm)) for (post_guid, post_title, post_desc, \ owner_id, owner_name, owner_username, time)\ @@ -219,16 +220,16 @@ def write_groupvideos_subsection (db, xml, group_guid): video_link=qry.post_content(db,post_guid, 477) prefix='videos/view/' - post_attr=wrt.pidstr(wrt.urlparticipa(prefix,str(post_guid))) + post_attr=strf.pidstr(strf.urlparticipa(prefix,str(post_guid))) wrt.write_open_tag(xml,3,"video",post_attr) prefix='profile/' - owner_attr=wrt.uidstr(wrt.urlparticipa(prefix,owner_username)) + owner_attr=strf.uidstr(strf.urlparticipa(prefix,owner_username)) wrt.write_tag(xml,4,"autor",owner_name,owner_attr) wrt.write_tag(xml,4,"titulo",post_title,'') - wrt.write_tag(xml,4,"data",wrt.datestr(time),'') - wrt.write_tag(xml,4,"link",'',wrt.hrefstr(video_link)) - wrt.write_tag(xml,4,"descricao",wrt.cdata(post_desc),'') + wrt.write_tag(xml,4,"data",strf.datestr(time),'') + wrt.write_tag(xml,4,"link",'',strf.hrefstr(video_link)) + wrt.write_tag(xml,4,"descricao",strf.cdata(post_desc),'') wrt.write_comments(db,xml,post_guid) @@ -249,7 +250,7 @@ def write_groupevents_subsection (db, xml, group_guid): # 54 = select * from elgg_metastrings where string='event_calendar_enable'; perm=qry.postcontent_permission(db, group_guid, 54) - wrt.write_open_tag(xml,2,"eventos",wrt.permstr(perm)) + wrt.write_open_tag(xml,2,"eventos",strf.permstr(perm)) for (post_guid, post_title, post_desc, \ owner_id, owner_name, owner_username, time)\ @@ -274,21 +275,21 @@ def write_groupevents_subsection (db, xml, group_guid): organizer=qry.post_content(db, post_guid, 30) prefix='event_calendar/view/' - post_attr=wrt.pidstr(wrt.urlparticipa(prefix,str(post_guid))) + post_attr=strf.pidstr(strf.urlparticipa(prefix,str(post_guid))) wrt.write_open_tag(xml,3,"evento",post_attr) prefix='profile/' - owner_attr=wrt.uidstr(wrt.urlparticipa(prefix,owner_username)) + owner_attr=strf.uidstr(strf.urlparticipa(prefix,owner_username)) wrt.write_tag(xml,4,"autor",owner_name,owner_attr) wrt.write_tag(xml,4,"titulo",post_title,'') - wrt.write_tag(xml,4,"data",wrt.datestr(time),'') + wrt.write_tag(xml,4,"data",strf.datestr(time),'') wrt.write_tag(xml,4,"organizador",organizer,'') wrt.write_tag(xml,4,"contato",contact,'') wrt.write_tag(xml,4,"endereco",venue,'') - wrt.write_tag(xml,4,"data_inicio",wrt.datestr(time_start),'') - wrt.write_tag(xml,4,"data_fim",wrt.datestr(time_end),'') + wrt.write_tag(xml,4,"data_inicio",strf.datestr(time_start),'') + wrt.write_tag(xml,4,"data_fim",strf.datestr(time_end),'') wrt.write_tag(xml,4,"taxa_participacao",fees,'') - wrt.write_tag(xml,4,"descricao",wrt.cdata(post_desc),'') + wrt.write_tag(xml,4,"descricao",strf.cdata(post_desc),'') wrt.write_close_tag(xml,3,"evento") @@ -307,17 +308,17 @@ def write_groups_section(db, xml, \ brief_desc=qry.post_content(db,guid, 45) prefix='groups/profile/' - group_attr=wrt.cidstr(wrt.urlparticipa(prefix,str(guid))) + group_attr=strf.cidstr(strf.urlparticipa(prefix,str(guid))) wrt.write_open_tag(xml,1,"comunidade",group_attr) # Write all group's information prefix='profile/' - owner_attr=wrt.uidstr(wrt.urlparticipa(prefix,owner_username)) + owner_attr=strf.uidstr(strf.urlparticipa(prefix,owner_username)) wrt.write_tag(xml,2,"proprietario",owner_name,owner_attr) wrt.write_tag(xml,2,"titulo",title,'') - wrt.write_tag(xml,2,"data",wrt.datestr(time),'') - wrt.write_tag(xml,2,"descricao",wrt.cdata(desc),'') - wrt.write_tag(xml,2,"breve_descricao",wrt.cdata(brief_desc),'') + wrt.write_tag(xml,2,"data",strf.datestr(time),'') + wrt.write_tag(xml,2,"descricao",strf.cdata(desc),'') + wrt.write_tag(xml,2,"breve_descricao",strf.cdata(brief_desc),'') if qry.groupaccess_permission(db, guid) == 'public': @@ -341,7 +342,7 @@ def write_singlefile_groups_section (db, dir_results): groups_info = db.cursor() groups_info.execute(qry.qry_groups_info) - xml_filename=dir_results+wrt.date_today()+"_comunidades"+".xml" + xml_filename=dir_results+strf.date_today()+"_comunidades"+".xml" xml = wrt.open_xml_file(xml_filename) wrt.write_open_tag(xml,0,"comunidades",'') diff --git a/lib/xml_support_functions.py b/lib/xml_support_functions.py index dd49756308db6b20b56dccb3eea6e0dc01b803f0..e471e8910944a7f9048fc8e0608ddf458347032b 100644 --- a/lib/xml_support_functions.py +++ b/lib/xml_support_functions.py @@ -25,6 +25,7 @@ import MySQLdb import codecs import datetime +import string_functions as strf import queries_definition as qry ###################################################################### @@ -37,101 +38,24 @@ def open_xml_file (xml_filename): return xml_file #--------------------------------------------------------------------# -#--------------------------------------------------------------------# -def date_today(): - return str(datetime.date.today()) -#--------------------------------------------------------------------# - -#--------------------------------------------------------------------# -def lvl (l): - if l == 1: - return "\t" - elif l == 2: - return "\t\t" - elif l == 3: - return "\t\t\t" - elif l == 4: - return "\t\t\t\t" - elif l == 5: - return "\t\t\t\t\t" - elif l == 6: - return "\t\t\t\t\t\t" - elif l == 7: - return "\t\t\t\t\t\t\t" - else: - return "" -#--------------------------------------------------------------------# - -#--------------------------------------------------------------------# -def cdata (string): - if len(string) > 0: - return "<![CDATA["+string+"]]>" - else: - return "" -#--------------------------------------------------------------------# - -#--------------------------------------------------------------------# -def uidstr (guid): - return " uid="+"\""+guid+"\"" -#--------------------------------------------------------------------# - -#--------------------------------------------------------------------# -def cidstr (guid): - return " cid="+"\""+guid+"\"" -#--------------------------------------------------------------------# - -#--------------------------------------------------------------------# -def pidstr (guid): - return " pid="+"\""+guid+"\"" -#--------------------------------------------------------------------# - -#--------------------------------------------------------------------# -def permstr (perm): - return " habilitado="+"\""+str(perm)+"\"" -#--------------------------------------------------------------------# - -#--------------------------------------------------------------------# -def qtystr (quantity): - return " quantidade="+"\""+str(quantity)+"\"" -#--------------------------------------------------------------------# - -#--------------------------------------------------------------------# -def urlparticipa (prefix, guid): - return "http://participatorio.juventude.gov.br/"+prefix+guid -#--------------------------------------------------------------------# - -#--------------------------------------------------------------------# -def hrefstr (url): - return " href="+"\""+url+"\"" -#--------------------------------------------------------------------# - -#--------------------------------------------------------------------# -def datestr (time): - if time != "": - return str(datetime.datetime.fromtimestamp(int(time))) - else: - return "" -#--------------------------------------------------------------------# - #--------------------------------------------------------------------# def write_open_tag (xml, l, tag_name, attr_str): - xml.write(lvl(l)+"<"+tag_name+attr_str+">"+"\n") + xml.write(strf.lvl(l)+"<"+tag_name+attr_str+">"+"\n") #--------------------------------------------------------------------# #--------------------------------------------------------------------# def write_close_tag (xml, l, tag_name): - xml.write(lvl(l)+"</"+tag_name+">"+"\n") + xml.write(strf.lvl(l)+"</"+tag_name+">"+"\n") #--------------------------------------------------------------------# #--------------------------------------------------------------------# def write_tag (xml, l, tag_name, info_str, attr_str): - level=lvl(l) if len(info_str) > 0: tag_begin=("<"+tag_name+attr_str+">") tag_end=("</"+tag_name+">") - xml.write(level+tag_begin+info_str+tag_end+"\n") + xml.write(strf.lvl(l)+tag_begin+info_str+tag_end+"\n") else: - xml.write(level+"<"+tag_name+attr_str+"/>"+"\n") + xml.write(strf.lvl(l)+"<"+tag_name+attr_str+"/>"+"\n") #--------------------------------------------------------------------# #--------------------------------------------------------------------# @@ -145,10 +69,10 @@ def write_comments (db, xml, post_guid): write_open_tag(xml,5,"comentario",'') prefix='profile/' - user_attr=uidstr(urlparticipa(prefix,user_username)) + user_attr=strf.uidstr(strf.urlparticipa(prefix,user_username)) write_tag(xml,6,"usuario",user_name,user_attr) - write_tag(xml,6,"data",datestr(time),'') - write_tag(xml,6,"mensagem",cdata(string),'') + write_tag(xml,6,"data",strf.datestr(time),'') + write_tag(xml,6,"mensagem",strf.cdata(string),'') write_close_tag(xml,5,"comentario") diff --git a/lib/xml_user_section.py b/lib/xml_user_section.py index 0ab16354f83e8581bc9606a43201fd3855ab711b..23ae68a7f5a62be0d47762813b139f364ceb347c 100644 --- a/lib/xml_user_section.py +++ b/lib/xml_user_section.py @@ -24,6 +24,7 @@ import MySQLdb import queries_definition as qry +import string_functions as strf import xml_support_functions as wrt ###################################################################### @@ -40,7 +41,7 @@ def write_userfriends_subsection (db, xml, user_guid): wrt.write_open_tag(xml,2,"amigos",'') for (friend_id, friend_name, friend_username) in friends_info: prefix='profile/' - friend_attr=wrt.uidstr(wrt.urlparticipa(prefix,friend_username)) + friend_attr=strf.uidstr(strf.urlparticipa(prefix,friend_username)) wrt.write_tag(xml,3,"usuario",friend_name,friend_attr) wrt.write_close_tag(xml,2,"amigos") @@ -55,7 +56,7 @@ def write_userowngroup_subsection (db, xml, user_guid): wrt.write_open_tag(xml,3,"dono",'') for (group_id, group_title) in user_owngroups: prefix='groups/profile/' - group_attr=wrt.cidstr(wrt.urlparticipa(prefix,str(group_id))) + group_attr=strf.cidstr(strf.urlparticipa(prefix,str(group_id))) wrt.write_tag(xml,4,"comunidade",group_title,group_attr) wrt.write_close_tag(xml,3,"dono") @@ -70,7 +71,7 @@ def write_usermembergroup_subsection (db, xml, user_guid): wrt.write_open_tag(xml,3,"participante",'') for (group_id, group_title) in user_membergroups: prefix='groups/profile/' - group_attr=wrt.cidstr(wrt.urlparticipa(prefix,str(group_id))) + group_attr=strf.cidstr(strf.urlparticipa(prefix,str(group_id))) wrt.write_tag(xml,4,"comunidade",group_title,group_attr) wrt.write_close_tag(xml,3,"participante") @@ -98,16 +99,16 @@ def write_userfiles_subsection (db, xml, user_guid): in user_files: prefix="file/download/" - file_link=wrt.urlparticipa(prefix,str(post_guid)) + file_link=strf.urlparticipa(prefix,str(post_guid)) prefix='file/view/' - post_attr=wrt.pidstr(wrt.urlparticipa(prefix,str(post_guid))) + post_attr=strf.pidstr(strf.urlparticipa(prefix,str(post_guid))) wrt.write_open_tag(xml,3,"arquivo",post_attr) wrt.write_tag(xml,4,"titulo",post_title,'') - wrt.write_tag(xml,4,"data",wrt.datestr(time),'') - wrt.write_tag(xml,4,"link",'',wrt.hrefstr(file_link)) - wrt.write_tag(xml,4,"descricao",wrt.cdata(post_desc),'') + wrt.write_tag(xml,4,"data",strf.datestr(time),'') + wrt.write_tag(xml,4,"link",'',strf.hrefstr(file_link)) + wrt.write_tag(xml,4,"descricao",strf.cdata(post_desc),'') wrt.write_comments(db,xml,post_guid) @@ -136,13 +137,13 @@ def write_userblogs_subsection (db, xml, user_guid): post_excerpt=qry.post_content(db,post_guid,64) prefix='blog/view/' - post_attr=wrt.pidstr(wrt.urlparticipa(prefix,str(post_guid))) + post_attr=strf.pidstr(strf.urlparticipa(prefix,str(post_guid))) wrt.write_open_tag(xml,3,"blog",post_attr) wrt.write_tag(xml,4,"titulo",post_title,'') - wrt.write_tag(xml,4,"data",wrt.datestr(time),'') - wrt.write_tag(xml,4,"resumo",wrt.cdata(post_excerpt),'') - wrt.write_tag(xml,4,"texto",wrt.cdata(post_desc),'') + wrt.write_tag(xml,4,"data",strf.datestr(time),'') + wrt.write_tag(xml,4,"resumo",strf.cdata(post_excerpt),'') + wrt.write_tag(xml,4,"texto",strf.cdata(post_desc),'') wrt.write_comments(db,xml,post_guid) @@ -169,13 +170,13 @@ def write_userbookmarks_subsection (db, xml, user_guid): bookmark_link=qry.post_content(db,post_guid,90) prefix='bookmarks/view/' - post_attr=wrt.pidstr(wrt.urlparticipa(prefix,str(post_guid))) + post_attr=strf.pidstr(strf.urlparticipa(prefix,str(post_guid))) wrt.write_open_tag(xml,3,"favorito",post_attr) wrt.write_tag(xml,4,"titulo",post_title,'') - wrt.write_tag(xml,4,"data",wrt.datestr(time),'') - wrt.write_tag(xml,4,"link",'',wrt.hrefstr(bookmark_link)) - wrt.write_tag(xml,4,"descricao",wrt.cdata(post_desc),'') + wrt.write_tag(xml,4,"data",strf.datestr(time),'') + wrt.write_tag(xml,4,"link",'',strf.hrefstr(bookmark_link)) + wrt.write_tag(xml,4,"descricao",strf.cdata(post_desc),'') wrt.write_comments(db,xml,post_guid) @@ -199,12 +200,12 @@ def write_userpages_subsection (db, xml, user_guid): in user_pages: prefix='pages/view/' - post_attr=wrt.pidstr(wrt.urlparticipa(prefix,str(post_guid))) + post_attr=strf.pidstr(strf.urlparticipa(prefix,str(post_guid))) wrt.write_open_tag(xml,3,"pagina",post_attr) wrt.write_tag(xml,4,"titulo",post_title,'') - wrt.write_tag(xml,4,"data",wrt.datestr(time),'') - wrt.write_tag(xml,4,"texto",wrt.cdata(post_desc),'') + wrt.write_tag(xml,4,"data",strf.datestr(time),'') + wrt.write_tag(xml,4,"texto",strf.cdata(post_desc),'') wrt.write_comments(db,xml,post_guid) @@ -231,13 +232,13 @@ def write_uservideos_subsection (db, xml, user_guid): video_link=qry.post_content(db, post_guid, 477) prefix='videos/view/' - post_attr=wrt.pidstr(wrt.urlparticipa(prefix,str(post_guid))) + post_attr=strf.pidstr(strf.urlparticipa(prefix,str(post_guid))) wrt.write_open_tag(xml,3,"video",post_attr) wrt.write_tag(xml,4,"titulo",post_title,'') - wrt.write_tag(xml,4,"data",wrt.datestr(time),'') - wrt.write_tag(xml,4,"link",'',wrt.hrefstr(video_link)) - wrt.write_tag(xml,4,"descricao",wrt.cdata(post_desc),'') + wrt.write_tag(xml,4,"data",strf.datestr(time),'') + wrt.write_tag(xml,4,"link",'',strf.hrefstr(video_link)) + wrt.write_tag(xml,4,"descricao",strf.cdata(post_desc),'') wrt.write_comments(db,xml,post_guid) @@ -280,18 +281,18 @@ def write_userevents_subsection (db, xml, user_guid): organizer=qry.post_content(db, post_guid, 30) prefix='event_calendar/view/' - post_attr=wrt.pidstr(wrt.urlparticipa(prefix,str(post_guid))) + post_attr=strf.pidstr(strf.urlparticipa(prefix,str(post_guid))) wrt.write_open_tag(xml,3,"evento",post_attr) wrt.write_tag(xml,4,"titulo",post_title,'') - wrt.write_tag(xml,4,"data",wrt.datestr(time),'') + wrt.write_tag(xml,4,"data",strf.datestr(time),'') wrt.write_tag(xml,4,"organizador",organizer,'') wrt.write_tag(xml,4,"contato",contact,'') wrt.write_tag(xml,4,"endereco",venue,'') - wrt.write_tag(xml,4,"data_inicio",wrt.datestr(time_start),'') - wrt.write_tag(xml,4,"data_fim",wrt.datestr(time_end),'') + wrt.write_tag(xml,4,"data_inicio",strf.datestr(time_start),'') + wrt.write_tag(xml,4,"data_fim",strf.datestr(time_end),'') wrt.write_tag(xml,4,"taxa_participacao",fees,'') - wrt.write_tag(xml,4,"descricao",wrt.cdata(post_desc),'') + wrt.write_tag(xml,4,"descricao",strf.cdata(post_desc),'') wrt.write_comments(db,xml,post_guid) @@ -307,7 +308,7 @@ def write_users_section (db, xml, \ guid, name, username): prefix='profile/' - user_attr=wrt.uidstr(wrt.urlparticipa(prefix,username)) + user_attr=strf.uidstr(strf.urlparticipa(prefix,username)) wrt.write_open_tag(xml,1,"usuario",user_attr) # Write all user's information @@ -336,7 +337,7 @@ def write_singlefile_users_section (db, dir_results): users_info = db.cursor() users_info.execute(qry.qry_users_info) - xml_filename=dir_results+wrt.date_today()+"_usuarios"+".xml" + xml_filename=dir_results+strf.date_today()+"_usuarios"+".xml" xml = wrt.open_xml_file(xml_filename) wrt.write_open_tag(xml,0,"usuarios",'')