コード例 #1
0
ファイル: erlple.py プロジェクト: dhq314/Erlample
 def post(self, action, param):
     if action == "adding":
         mid = self.get_argument("mid", None)
         func_name = self.get_argument("func_name", None).replace("'", "`")
         func_html = self.get_argument("func_html", None).replace("'", "`")
         func_desc = self.get_argument("func_desc", None).replace("'", "`")
         func_usage = self.get_argument("func_usage",
                                        None).replace("'", "`")
         pg = pgsql.Pgsql()
         sql = "SELECT * FROM funcs WHERE mid = " + str(
             mid) + " and name = '" + func_name + "'"
         rs = pg.fetchone(sql)
         if not rs and mid.isdigit() and func_name and func_html:
             pg.query(
                 "INSERT INTO funcs(name, mid, html, describe, usage) values('"
                 + func_name + "', " + mid + ", '" + func_html + "', '" +
                 func_desc + "', '" + func_usage + "')")
     elif action == "updating":
         fid = self.get_argument("fid", None)
         mid = self.get_argument("mid", None)
         func_name = self.get_argument("func_name", None).replace("'", "`")
         func_html = self.get_argument("func_html", None).replace("'", "`")
         func_desc = self.get_argument("func_desc", None).replace("'", "`")
         func_usage = self.get_argument("func_usage",
                                        None).replace("'", "`")
         if fid.isdigit() and mid.isdigit() and func_name and func_html:
             pg = pgsql.Pgsql()
             pg.query("UPDATE funcs SET name = '" + func_name +
                      "', mid = " + mid + ", html = '" + func_html +
                      "', describe = '" + func_desc + "', usage = '" +
                      func_usage + "' WHERE id = " + fid)
     create_erlple_file = os.path.join(os.path.dirname(__file__),
                                       'create_erlple.py')
     os.system("python %s" % create_erlple_file)
     self.redirect("/fun/")
コード例 #2
0
ファイル: erlple.py プロジェクト: dhq314/Erlample
 def get(self, action, mid):
     if action == "add":
         self.render("mod_action.html", rs=None)
     elif action == "del":
         # mid = mid.strip()
         # if mid.isdigit():
         #     sql = "DELETE FROM mod WHERE id = " + mid
         #     pg = pgsql.Pgsql()
         #     pg.query(sql)
         self.redirect("/")
     elif action == "up":
         mid = mid.strip()
         if mid.isdigit():
             pg = pgsql.Pgsql()
             rs = pg.fetchone("SELECT * FROM mod WHERE id = " + str(mid))
             self.render("mod_action.html", rs=rs)
         else:
             self.redirect("/")
     elif action == "get_func_list":
         pg = pgsql.Pgsql()
         rs = pg.fetchall("SELECT name FROM funcs WHERE mid = " + str(mid))
         ret = ""
         for r in rs:
             ret = ret + r['name'] + ","
         ret = ret.strip(",")
         self.write(ret)
     elif action == "get_mod_list":
         ret = {}
         pg = pgsql.Pgsql()
         rs = pg.fetchall("SELECT id, name FROM mod")
         for r in rs:
             func_num = pg.fetch_num("SELECT id FROM funcs WHERE mid = " +
                                     str(r['id']))
             ret[r['id']] = {"name": r['name'], "func_num": func_num}
         self.write(json_encode(ret))
コード例 #3
0
ファイル: util.py プロジェクト: dhq314/Erlample
def page(self, per_page, total_sql):
    """
    分页函数
    """
    pg = pgsql.Pgsql()
    total_num = pg.fetch_num(total_sql)
    total_page = ceil2(total_num, per_page)

    query_args = parse_qs(self.request.uri)
    if 'page' in query_args.keys():
        cur_page = query_args['page']
        cur_page = cur_page.strip()
        if cur_page.isdigit():
            cur_page = int(cur_page)
            if cur_page < 1:
                cur_page = 1
        else:
            cur_page = 1
    else:
        cur_page = 1

    prev_page = cur_page - 1
    if prev_page < 1:
        prev_page = 1
    next_page = cur_page + 1
    if next_page > total_page:
        next_page = total_page
    offset = (cur_page - 1) * per_page
    range_page = 4
    show_items = (range_page * 2) + 1
    return cur_page, total_num, total_page, prev_page, next_page, offset, range_page, show_items
コード例 #4
0
ファイル: erlple.py プロジェクト: dhq314/Erlample
    def get(self):
        per_page = 20
        total_sql = "SELECT id FROM mod"
        cur_page, total_num, total_page, prev_page, next_page, offset, range_page, show_items = \
            util.page(self, per_page, total_sql)

        pg = pgsql.Pgsql()
        ms = pg.fetchall(
            "SELECT id, name, describe, html FROM mod LIMIT %d OFFSET %d" %
            (per_page, offset))
        mod_list = []
        for m in ms:
            m['func_num'] = pg.fetch_num(
                "SELECT id FROM funcs WHERE mid = %d" % m['id'])
            mod_list.append(m)
        template_variables = dict(mod_list=mod_list,
                                  cur_page=cur_page,
                                  total_num=total_num,
                                  total_page=total_page,
                                  prev_page=prev_page,
                                  next_page=next_page,
                                  range_page=range_page,
                                  show_items=show_items,
                                  url="/mod/")
        self.render("mod_list.html", **template_variables)
コード例 #5
0
ファイル: erlple.py プロジェクト: dhq314/Erlample
 def get(self, action, fid):
     if action == "add":
         current_mid = None
         if fid.isdigit():
             current_mid = int(fid)
         pg = pgsql.Pgsql()
         ms = pg.fetchall("SELECT id, name FROM mod")
         mod_list = []
         for m in ms:
             m['func_num'] = pg.fetch_num(
                 "SELECT id FROM funcs WHERE mid = %d" % m['id'])
             mod_list.append(m)
         template_variables = dict(ms=mod_list,
                                   fs=None,
                                   current_mid=current_mid,
                                   funname=None)
         self.render("fun_action.html", **template_variables)
     elif action == "up":
         fid = fid.strip()
         if fid.isdigit():
             pg = pgsql.Pgsql()
             ms = pg.fetchall("SELECT id, name FROM mod")
             mod_list = []
             for m in ms:
                 m['func_num'] = pg.fetch_num(
                     "SELECT id FROM funcs WHERE mid = %d" % m['id'])
                 mod_list.append(m)
             fs = pg.fetchone(
                 "SELECT id, name, describe, usage, html, mid FROM funcs WHERE id = %s"
                 % fid)
             template_variables = dict(ms=mod_list,
                                       fs=fs,
                                       current_mid=None,
                                       funname=None)
             self.render("fun_action.html", **template_variables)
         else:
             self.redirect("/fun/")
     elif action == "del":
         # fid = fid.strip()
         # if fid.isdigit():
         #     sql = "DELETE FROM funcs WHERE id = " + str(fid)
         #     pg = pgsql.Pgsql()
         #     pg.query(sql)
         self.redirect("/fun/")
     else:
         self.redirect("/fun/")
コード例 #6
0
ファイル: erlple.py プロジェクト: dhq314/Erlample
    def get(self, mid):
        uri = "/fun/"
        condition = ""
        current_mid = None
        if mid.isdigit():
            condition = "WHERE mid = %s" % mid
            current_mid = mid
            uri += mid

        per_page = 50
        total_sql = "SELECT id FROM funcs %s" % condition
        cur_page, total_num, total_page, prev_page, next_page, offset, range_page, show_items = \
            util.page(self, per_page, total_sql)

        pg = pgsql.Pgsql()
        fs = pg.fetchall(
            "SELECT id, name, mid, describe FROM funcs %s ORDER BY id DESC LIMIT %d OFFSET %d"
            % (condition, per_page, offset))

        i = len(fs)
        if i > 0:
            ms = pg.fetchall("SELECT id, name FROM mod ORDER BY name ASC")
            mod_name_dict = {}
            for m in ms:
                mod_name_dict[m['id']] = m['name']
            rs = []
            config_data = get_config_data()
            i = 1
            for f in fs:
                f['index'] = i
                if f['mid'] == 0 or f['mid'] == "0":
                    mod_name = "no_mod_name"
                else:
                    mod_name = mod_name_dict[f['mid']]
                url = config_data['web_url'] + "modules/" + mod_name + "/" + \
                      f['name'].replace("/", "_") + ".html?search=" + mod_name + ":"
                f['mod_name'] = mod_name
                f['url'] = url
                rs.append(f)
                i += 1
        else:
            rs = None
        template_variables = dict(rs=rs,
                                  current_mid=current_mid,
                                  cur_page=cur_page,
                                  total_num=total_num,
                                  total_page=total_page,
                                  prev_page=prev_page,
                                  next_page=next_page,
                                  range_page=range_page,
                                  show_items=show_items,
                                  url=uri)
        self.render("fun_list.html", **template_variables)
コード例 #7
0
ファイル: erlple.py プロジェクト: dhq314/Erlample
 def post(self, action, param):
     if action == "adding":
         mod_name = self.get_argument("mod_name", None).replace("'", "`")
         mod_desc = self.get_argument("mod_desc", None).replace("'", "`")
         if mod_name and mod_desc:
             mod_html = self.get_argument("mod_html", "").replace("'", "`")
             sql = "INSERT INTO mod(name, describe, html) values('" + mod_name + "', '" + \
                   mod_desc + "', '" + mod_html + "')"
             pg = pgsql.Pgsql()
             pg.query(sql)
     elif action == "updating":
         mid = self.get_argument("mid", None)
         mod_name = self.get_argument("mod_name", None).replace("'", "`")
         mod_desc = self.get_argument("mod_desc", None).replace("'", "`")
         if mid.isdigit() and mod_name and mod_desc:
             mod_html = self.get_argument("mod_html", "").replace("'", "`")
             sql = "UPDATE mod SET name = '" + mod_name + "', describe = '" + mod_desc + "', html = '" + \
                   mod_html + "' WHERE id = " + str(mid)
             pg = pgsql.Pgsql()
             pg.query(sql)
     self.redirect("/")
コード例 #8
0
ファイル: main.py プロジェクト: pyrotank41/ThreeComa
def addAssetsListToDB():

    asset_list_alpaca = alp.getAssets()
    db_instance = pgsql.Pgsql("postgres", "password", "test", "localhost")
    # deleting previous information and inserting new one.
    # need to change tghis approach in future as we shall not select, just update.
    db_instance.executeQuery("delete from assets_alpaca;")

    for i in asset_list_alpaca:
        q = f'''INSERT INTO assets_alpaca (ticker, name, exchange, tradable, shortable, marginable) 
            VALUES ('{i[0]}','{i[1]}','{i[2]}','{'T' if i[3] else 'F'}','{'T' if i[4] else 'F'}', '{'T' if i[5] else 'F'}');'''
        db_instance.executeQuery(q)
コード例 #9
0
ファイル: erlple.py プロジェクト: dhq314/Erlample
 def get(self, action, mid, func_name):
     # print func_name
     if action == "add":
         current_mid = None
         if mid.isdigit():
             current_mid = int(mid)
         pg = pgsql.Pgsql()
         ms = pg.fetchall("SELECT id, name FROM mod")
         mod_list = []
         for m in ms:
             m['func_num'] = pg.fetch_num(
                 "SELECT id FROM funcs WHERE mid = %d" % m['id'])
             mod_list.append(m)
         func_name = func_name.replace("-", "/")
         template_variables = dict(ms=mod_list,
                                   fs=None,
                                   current_mid=current_mid,
                                   funname=func_name)
         self.render("fun_action.html", **template_variables)
コード例 #10
0
def get_pg_metadata():
    pg_metadata = pgsql.Pgsql("10.0.138.20", "postgres", "", "gscloud_metadata")
    return pg_metadata
コード例 #11
0
def get_pg_src():
    pg_src = pgsql.Pgsql("10.0.138.20", "postgres", "", "gscloud")
    return pg_src
コード例 #12
0
ファイル: shp_into_pgsql.py プロジェクト: pkuazi/shp_ruku
'''
import pgsql
import os
import shapely, fiona
from asn1crypto._ffi import null
import datetime
from osgeo import ogr,osr
import json
from geotrans import GeomTrans

# data_root = "/mnt/gscloud/LANDSAT"
shp_path = "/mnt/win/phd/samples/pd_1995"
shp_file = os.path.join(shp_path,'PD_1995_120035.shp')
# geojson=os.path.join(shp_path, 'pd_1995_120035.geojson')

pg_src = pgsql.Pgsql("10.0.85.20", "postgres", "", "mark")
# def parse_shp_to_geojson(shpfile):
#     return geojson
import uuid
def labels_into_pgsql(geom, labelid,proj):
    sampletype =0;
    imageres=30;
    imageid="LC81200342015133LGN00";
    taskid = 11;
    tagid=labelid;
#     insert_sql = """INSERT INTO public.samples(
#             img, gid, userid, label, geom, ctime, taskid, name, abstract, 
#             sampleid, data, year, id, projection, type, source)
#     VALUES (0, null, 0, %s, %s, %s,  %s, %s, null, %s, null, 2015, %s, %s, %s, 1);  """
    mtime = datetime.datetime.now()
    guid=str(uuid.uuid4()).replace('-','')
コード例 #13
0
ファイル: main.py プロジェクト: pyrotank41/ThreeComa
import psycopg2  # for
import datetime
import time

#user defined imports ----------------------------------------------------------
sys.path.insert(1, './nasdaq')
import tickers
import alpaca
import pgsql
import config  # FIXME use config_api, this import is for development only

print("*****************************************************************")
print("** Hello Money Makers, Welcome to the best tool to make money! **")
print("*****************************************************************\n")

db = pgsql.Pgsql("postgres", "password", "test", "localhost")
alp = alpaca.Alpaca(config.ALPACA_PAPER_API_KEY, config.ALPACA_PAPER_SECRET)


# updateTickerList --------------------------------------------------------------
# A simple function that updates the list of tickers in nasdaq and other exchanges
# its is to be used only once or a few times a day (need to work on the frequency of the usage)
def updateTickerList():
    tickers.downloadNasdaqListed()
    tickers.downloadOtherListed()


def addAssetsListToDB():

    asset_list_alpaca = alp.getAssets()
    db_instance = pgsql.Pgsql("postgres", "password", "test", "localhost")
コード例 #14
0
import fiona
import pgsql
from shapely.geometry import mapping, Polygon

pg_src = pgsql.Pgsql("10.0.81.35", "2345", "postgres", "", "gscloud_metadata")


def region_search_dem(min_lat, max_lat, min_long, max_long, dst_shp):
    data_sql = '''SELECT id, dataid, name, "path", "row",  lt_long, lt_lat,  rb_long, rb_lat,the_geom FROM public.metadata_dem_gdem where rb_long>%s and lt_long<%s and rb_lat<%s and lt_lat>%s ORDER BY row DESC;''' % (
        min_long, max_long, max_lat, min_lat)
    dem_data = pg_src.getAll(data_sql)
    num = len(dem_data)

    #output bounding box into shp
    dataid_list = []

    # schema is a dictory
    schema = {
        'geometry': 'Polygon',
        'properties': {
            'id': 'int',
            'dataid': 'str',
            'path': 'int',
            'row': 'int'
        }
    }
    #  use fiona.open
    with fiona.open(dst_shp,
                    mode='w',
                    driver='ESRI Shapefile',
                    schema=schema,
コード例 #15
0
    with open(config_file, 'rb') as fp:
        config = json.load(fp)

    WEB_NAME = config['web_name']
    WEB_URL = config['web_url']
    ACT_URL = config['act_url']

    BASE_DIR = os.path.dirname(os.path.abspath(__file__))

    PUB_DIR = BASE_DIR + "/public_html/"

    # 资源目录
    ASSETS_DIR = BASE_DIR + "/assets/"
    # 生成模块目录
    MODULES_DIR = PUB_DIR + "modules/"

    os.system("rm -rf " + PUB_DIR + "*")
    os.system("cp -r " + ASSETS_DIR + " " + PUB_DIR)
    os.system("mkdir -p " + MODULES_DIR)

    root_directory = os.path.join(os.path.dirname(__file__),
                                  "templates/create")
    tpl = tornado.template.Loader(root_directory)
    pg = pgsql.Pgsql()
    mod_list = pg.fetchall("SELECT * FROM mod ORDER BY name ASC")
    create_index(mod_list)
    create_mod_list()
    create_func_list()
    create_erldocs_index(mod_list)
    print "Generate %s HTML DONE!" % WEB_NAME