{"$set": { "cics_loc": cics_loc }}) #if not "nm_loc" in mp: if "nm_geocode" in ml: score = -1 nm_max = None for nm in ml["nm_geocode"]: if ("importance" in nm) and (float(nm["importance"]) > score): nm_max = nm score = float(nm["importance"]) if nm_max: nm_loc = { "type": "Point", "coordinates": [nm_max["lon"], nm_max["lat"]] } mandi_prices.update({"_id": mp["_id"]}, {"$set": { "nm_loc": nm_loc }}) if __name__ == "__main__": config = get_config(get_env()) geocoder = Geocoder(config=config) geocoder.check_mandi_locations() geocoder.create_batch_geocodes()
"min_price": t["Min_x0020_Price"], "modal_price": t["Modal_x0020_Price"], "state": t["State"], "variety": t["Variety"] } if "Commodity" in t: obj["commodity"] = t["Commodity"] elif "Column1" in t: obj["commodity"] = t["Column1"] else: logger.warn("Commodity not found in %s" % t["@diffgr:id"]) continue logger.debug("Inserted %s %s %s" % (obj["commodity"], obj["market"], obj["arrival_date"])) data.append(obj) mongo_helper = MongoHelper(config) mongo_helper.rename_collection("mandi_prices") mongo_helper.save("mandi_prices", docs=data) if __name__ == "__main__": config = get_config(env=get_env()) xmlfile = download_file() if xmlfile: logger.info("Downloaded %s" % xmlfile) run_ingest(config, xmlfile) else: logger.warn("Latest file %s already ingested" % xmlfile)
mandi_prices.update({"_id": mp["_id"]}, {"$set": {"cics_loc": cics_loc}}) if isinstance(ml["cics_geocode"], dict): cics_loc = { "type": "Point", "coordinates": [float(ml["cics_geocode"]["@lng"]), float(ml["cics_geocode"]["@lat"])] } mandi_prices.update({"_id": mp["_id"]}, {"$set": {"cics_loc": cics_loc}}) #if not "nm_loc" in mp: if "nm_geocode" in ml: score = -1 nm_max = None for nm in ml["nm_geocode"]: if ("importance" in nm) and (float(nm["importance"]) > score): nm_max = nm score = float(nm["importance"]) if nm_max: nm_loc = { "type": "Point", "coordinates": [nm_max["lon"], nm_max["lat"]] } mandi_prices.update({"_id": mp["_id"]}, {"$set": {"nm_loc": nm_loc}}) if __name__ == "__main__": config = get_config(get_env()) geocoder = Geocoder(config=config) geocoder.check_mandi_locations() geocoder.create_batch_geocodes()
"max_price": t["Max_x0020_Price"], "min_price": t["Min_x0020_Price"], "modal_price": t["Modal_x0020_Price"], "state": t["State"], "variety": t["Variety"] } if "Commodity" in t: obj["commodity"] = t["Commodity"] elif "Column1" in t: obj["commodity"] = t["Column1"] else: logger.warn("Commodity not found in %s" % t["@diffgr:id"]) continue logger.debug("Inserted %s %s %s" % (obj["commodity"], obj["market"], obj["arrival_date"])) data.append(obj) mongo_helper = MongoHelper(config) mongo_helper.rename_collection("mandi_prices") mongo_helper.save("mandi_prices", docs=data) if __name__ == "__main__": config = get_config(env=get_env()) xmlfile = download_file() if xmlfile: logger.info("Downloaded %s" % xmlfile) run_ingest(config, xmlfile) else: logger.warn("Latest file %s already ingested" % xmlfile)
# this file runs the eve application and declares additional endpoints # for FB authentication from flask import make_response, request, jsonify, json from eve import Eve from priceprobi.utils import get_env from priceprobi.config import get_config from auth import get_pp_user, PPApiBasicAuth from priceprobi.utils import get_magic_user, Encoder from . import crossdomain __author__ = 'ujjwal' #get environmnet DEVELOPMENT or PRODUCTION env = get_env() api_settings = get_config(env) #instatiate Eve with dev or prod settings and basic http authentication app = Eve(settings=api_settings, auth=PPApiBasicAuth) #use custom json serialization since default flask serializer doesn't handle datetimes app.json_encoder = Encoder def _mandiprices_geojson(_items): features = [] for _item in _items: if "cics_loc" in _item: properties = { "_id": str(_item["_id"]), "arrival_date": _item["arrival_date"],