import MySQLdb import itertools import csv import os import types import sys import traceback from datetime import date import datetime from ckanapi import RemoteCKAN from pushers.penduduk_pusher import PendudukPusher from pushers.keluarga_pusher import KeluargaPusher from pushers.apbdes_pusher import ApbdesPusher from utils import open_cfg conf = open_cfg('../common/app.cfg') db = MySQLdb.connect(host=conf.MYSQL_HOST, user=conf.MYSQL_USER, passwd=conf.MYSQL_PASSWORD, db=conf.MYSQL_DB) #ckan = RemoteCKAN("http://ckan.neon.microvac:5000", apikey="8306ed32-78f3-4f1a-b7e6-b56f9e4f91e4") ckan = RemoteCKAN(conf.CKAN_HOST, apikey=conf.CKAN_KEY) # you must create a Cursor object. It will let # you execute all the queries you need cur = db.cursor(MySQLdb.cursors.DictCursor) # Use all the SQL you like cur.execute("""
for old_row in old_content["data"]: if isinstance(old_row, list): new_content["data"].append(old_row) elif isinstance(old_row, dict): new_row = [None] * column_length for i in range(column_length): new_row[i] = old_row.get(str(i)) new_content["data"].append(new_row) else: print "cannot handle %s" % str(old_row) return new_content if __name__ == "__main__": conf = open_cfg('../app.cfg') db = MySQLdb.connect(host=conf.MYSQL_HOST, user=conf.MYSQL_USER, passwd=conf.MYSQL_PASSWORD, db=conf.MYSQL_DB) cur = db.cursor(MySQLdb.cursors.DictCursor) query = "select blog_id, domain from sd_desa" cur.execute(query) desas = list(cur.fetchall()) count = 0 for desa in desas: cur.execute( "select id, content, timestamp, date_created from sd_contents where desa_id=%s and type = 'penduduk' and api_version<>'2.0' order by timestamp desc limit 1", (desa["blog_id"], )) sql_row_penduduk = cur.fetchone() if sql_row_penduduk is not None:
import MySQLdb import itertools import csv import os import types import sys import traceback import json from datetime import date import datetime from utils import open_cfg conf = open_cfg('app.cfg') db = MySQLdb.connect(host=conf.MYSQL_HOST, user=conf.MYSQL_USER, passwd=conf.MYSQL_PASSWORD, db=conf.MYSQL_DB) # you must create a Cursor object. It will let # you execute all the queries you need cur = db.cursor(MySQLdb.cursors.DictCursor) # Use all the SQL you like cur.execute(""" SELECT * FROM sd_contents c left join sd_desa d on d.blog_id = c.desa_id WHERE c.type = 'penduduk' and c.date_opendata_pushed is null """)