예제 #1
0
파일: seed.py 프로젝트: fireyy/spyder
def set_filter(seed_id, field_id):
    filter_model = Filter(current_app)
    filters_list = filter_model.list()
    seed_filter_model = Seed_filter(current_app)
    tmps = seed_filter_model.list(seed_id, field_id, order="list_order ASC")
    all_filters = []
    filters_data = {}
    tmps = tmps.list()
    for filter_item in tmps:
        filters_data[str(filter_item["filter_id"])] = filter_item
    for filter_item in filters_list:
        filter_id = str(filter_item["id"])
        if filters_data.get(filter_id):
            filters_data[filter_id]["title"] = filter_item["title"]
            filters_data[filter_id]["description"] = filter_item["description"]
            filters_data[filter_id]["profile"] = filters_data[filter_id]["profile"].encode("utf-8")
            filters_data[filter_id]["profile"] = phpserialize.loads(
                filters_data[filter_id]["profile"], decode_strings=True
            )
        if filter_item["config"]:
            filter_item["config"] = phpserialize.loads(filter_item["config"])
            filter_item["config"] = filter_item["config"].items()
            filter_item["config"].sort()
        all_filters.append(filter_item)
    filters_sort_data = {}
    for filters_item in filters_data:
        filters_sort_data[filters_data[filters_item]["list_order"]] = filters_data[filters_item]
    return render_template("seed/filter.html", filters=filters_sort_data, all_filters=all_filters, field_id=field_id)
예제 #2
0
파일: site.py 프로젝트: fireyy/spyder
def edit(site_id):
    site = Site(current_app)
    hook_funcs = [];
    attrs = dir(hooks);
    for attr in attrs:
        if attr.find("__") == -1:
            hook_funcs.append(attr)
    if request.method == "POST":
        name = request.form.get("name")
        url = request.form.get("url")
        descript = request.form.get("descript")
        sync_type = request.form.get("sync_type")
        if not name:
            error = "请输入站点名称"
        elif not url:
            error = "请输入站点链接"
        elif not sync_type:
            error = "请选择入库方式"
        else:
            site = Site(current_app)
            sync_profile = {
                "staticUrl": request.form.get("staticUrl"),
                "staticType": request.form.get("staticType"),
                "mysql_server": request.form.get("mysql_server"),
                "mysql_dbname": request.form.get("mysql_dbname"),
                "mysql_prefix": request.form.get("mysql_prefix"),
                "mysql_username": request.form.get("mysql_username"),
                "mysql_password": request.form.get("mysql_password"),
                "ftp_server": request.form.get("ftp_server"),
                "ftp_port": request.form.get("ftp_port"),
                "ftp_path": request.form.get("ftp_path"),
                "ftp_username": request.form.get("ftp_username"),
                "ftp_password": request.form.get("ftp_password"),
                "access_id": request.form.get("access_id"),
                "secret_access_key": request.form.get("secret_access_key"),
                "hook_func": request.form.get("hook_func"),
                "api_url": request.form.get("api_url")
            }
            sync_profile = phpserialize.dumps(sync_profile)
            site.edit(id=site_id, name=name, url=url, descript=descript, sync_type=sync_type, sync_profile=sync_profile)
            return redirect(url_for('sites.index'))
    per = site.view(site_id)[0]
    if per["sync_profile"]:
        per["sync_profile"] = phpserialize.loads(per["sync_profile"])
    field = Field(current_app)
    types = field.getSeedType()
    site_map = Site_map(current_app)
    website_maps = site_map.list(site_id)
    maps = {}
    for website_map in website_maps:
        if website_map["seed_type"] not in maps:
            maps[website_map["seed_type"]] = website_map
    return render_template("site/add.html", site=per, types=types, maps=maps, hook_funcs=hook_funcs)
예제 #3
0
파일: db.py 프로젝트: valeriansaliou/medius
def read(window, type):
	current_path = path(window, type)
	
	if os.path.exists(current_path):
		store_file = open(current_path, 'r')
		store_data = store_file.read()
		store_file.close()
		
		if(store_data):
			return phpserialize.loads(store_data)
		
		return None
	
	return None
예제 #4
0
파일: seed.py 프로젝트: fireyy/spyder
def edit(seed_id):
    tags = []
    alltags = []
    if request.method == "POST" and request.form.get("sid"):
        sid = request.form.get("sid")
        enabled = checkboxVal(request.form.get("enabled"))
        list1 = {
            "urlformat": request.form.get("urlformat"),
            "urltype": request.form.get("urltype"),
            "startpage": request.form.get("startpage"),
            "maxpage": request.form.get("maxpage"),
            "step": request.form.get("step"),
            "zero": request.form.get("zero"),
            "listparent": request.form.get("listparent"),
            "entryparent": request.form.get("entryparent"),
            "contenturl": request.form.get("contenturl"),
            "contentparent": request.form.get("contentparent"),
            "pageparent": request.form.get("pageparent"),
            "filters": request.form.get("filters"),
        }
        time1 = int(time.time())
        save = {
            "type": request.form.get("type"),
            "seed_name": request.form.get("seed_name"),
            "charset": request.form.get("charset"),
            "frequency": float(request.form.get("frequency")) * 3600,
            "timeout": request.form.get("timeout"),
            "tries": request.form.get("tries"),
            "enabled": enabled,
            "listtype": request.form.get("listtype"),
            "lang": request.form.get("lang"),
            "update_time": time1,
            "rule": phpserialize.dumps(list1),
        }
        field = Field(current_app)
        fields = field.list(save["type"]).list()
        guid_rule_datas = request.form.get("guid_rule")
        save["guid_rule"] = getFeildIdByTitle(guid_rule_datas, save["type"])
        seed = Seed(current_app)
        msg = seed.edit(sid, **save)
        seed_field = Seed_fields(current_app)
        # filter_model = Filter(current_app)
        # filters_org_data = filter_model.list()
        seed_filter_model = Seed_filter(current_app)
        # filters_data = {}
        # for filter_item in filters_org_data:
        #     filters_data[str(filter_item["id"])] = filter_item
        for field in fields:
            field_data = seed_field.view(sid, field.id).list()
            if len(field_data) > 0:
                seed_field.edit(
                    sid,
                    field.id,
                    request.form.get(field.name),
                    request.form.get("page_type_" + field.name),
                    request.form.get("fetch_all_" + field.name),
                )
            else:
                seed_value = {}
                seed_value["seed_id"] = sid
                seed_value["field_id"] = field.id
                seed_value["value"] = request.form.get(field.name)
                seed_value["page_type"] = request.form.get("page_type_" + field.name)
                seed_value["fetch_all"] = (
                    request.form.get("fetch_all_" + field.name) and request.form.get("fetch_all_" + field.name) or 0
                )
                seed_field.add(**seed_value)
            # 更改过滤规则
            filter_ids = request.form.getlist("filter" + str(field.id) + "[]")
            order_ct = 0
            if len(filter_ids) > 0 and filter_ids[0] != "none":
                seed_filter_model.remove(sid, field.id)
                for filter_id in filter_ids:
                    filter_item = request.form.getlist("profile_" + str(field.id) + "_" + str(filter_id) + "[]")
                    tmp = {}
                    ct = 0
                    for config in filter_item:
                        v = request.form.get(config + "_" + str(field.id) + "_" + filter_id)
                        if not v:
                            ct = ct + 1
                        tmp[config] = v
                    if ct != len(filter_item):
                        order_ct = order_ct + 1
                        filter_save = {
                            "sid": int(sid),
                            "field_id": int(field.id),
                            "filter_id": int(filter_id),
                            "profile": phpserialize.dumps(tmp),
                            "list_order": int(order_ct),
                        }
                        seed_filter_model.add(**filter_save)
        # 更改标签
        tags_data = request.form.get("tags")
        tags_data = tags_data.split(",")
        tags_model = Tags(current_app)
        seed_tag = Seed_tag(current_app)
        current_tags_data = seed_tag.list(sid)
        del_tags_data = {}
        for current_tag in current_tags_data:
            del_tags_data[current_tag["tid"]] = current_tag
        for tag in tags_data:
            tag = tag.strip()
            if tag:
                ishere = tags_model.findByName(tag).list()
                if len(ishere) > 0:
                    tid = ishere[0]["id"]
                else:
                    tid = tags_model.add(name=tag)
                if tid in del_tags_data:
                    del del_tags_data[tid]
                ishere = seed_tag.view(sid, tid).list()
                if len(ishere) == 0:
                    seed_tag.add(sid=sid, tid=tid)
        for k in del_tags_data:
            seed_tag.remove(del_tags_data[k]["sid"], del_tags_data[k]["tid"])
        url = getReferer()
        url = url and url or url_for("seeds.index")
        return redirect(url)
    if request.method == "GET" and seed_id > 0:
        setReferer()
        size = request.cookies.get("editorSize")
        if not size:
            size = 50
        seed = Seed(current_app)
        seed_data = seed.view(seed_id)[0]
        seed_type = seed_data["type"]
        seed_field = getSeedFieldsBySid(seed_id, seed_type)
        seed_fields = Seed_fields(current_app)
        page_types = seed_fields.getpageType()
        seed_data["frequency"] = float(seed_data["frequency"]) / float(3600)
        if seed_data["rule"]:
            seed_data["rule"] = seed_data["rule"].encode("utf-8")
            seed_data["rule"] = phpserialize.loads(seed_data["rule"], decode_strings=True)
        # 获取GUID规则
        if seed_data["guid_rule"]:
            seed_data["guid_rule"] = getFeildTitleById(seed_data["guid_rule"], seed_type)
        # 取出标签
        seed_tag = Seed_tag(current_app)
        tags_model = Tags(current_app)
        tags_data = seed_tag.list(seed_id)
        for tag in tags_data:
            tmp = tags_model.view(tag["tid"])[0]
            tags.append(tmp["name"])
        alltags_data = tags_model.list()
        for tag in alltags_data:
            alltags.append(tag["name"])
    return render_template(
        "seed/add.html",
        seed_type=seed_type,
        fields=seed_field,
        seed_data=seed_data,
        sid=seed_id,
        page_types=page_types,
        tags=tags,
        alltags=alltags,
        size=size,
    )