Exemplo n.º 1
0
def shortit():
  if 'org_url' in request.form:
    org_url = request.form.get('org_url')
    expired_at = int(time.mktime(time.strptime(request.form.get('expired_at','2038-01-19'), "%Y-%m-%d")))
    project = request.form.get('project',None)
    src = request.form.get('src','suoim')
    submitter = request.form.get('submitter',None)
    utm_source = request.form.get('utm_source',None)
    utm_medium = request.form.get('utm_medium',None)
    utm_campaign = request.form.get('utm_campaign',None)
    utm_content = request.form.get('utm_content',None)
    utm_term = request.form.get('utm_term',None)
    url_addon = encode_urlutm(utm_source=utm_source,utm_medium=utm_medium,utm_campaign=utm_campaign,utm_content=utm_content,utm_term=utm_term)
    if '?' in org_url:
      longurl = org_url+'&'+url_addon
    else:
      longurl = org_url+'?'+url_addon
    urllist,urlstatus = check_long_url(long_url=longurl)
    if urlstatus == 'exist':
      returnjson = {'result':urlstatus,'urllist':urllist}
      return jsonify(returnjson)
    else:
      check_short_status = 'success'
      while check_short_status == 'success':
        if src =='suoim':
          src_short_url,status = get_suoim_short_url(long_url=longurl)
        else:
          return jsonify({'result':'error','urllist':'src:'+src+'不存在'})
        if status == 'ok':
          check_short_result,check_short_status = get_long_url_from_short(src_short_url)
          if check_short_status == 'success':
            continue
          break
      short_url = src_short_url.split('/')[-1]
      insert_count = insert_shortcut(project=project,short_url=short_url,long_url=longurl,expired_at=expired_at,src=src,src_short_url=src_short_url,submitter=submitter,utm_source=utm_source,utm_medium=utm_medium,utm_campaign=utm_campaign,utm_content=utm_content,utm_term=utm_term)
      print('已插入短连接解析地址'+str(insert_count))
      urllist,urlstatus = check_long_url(long_url=longurl)
      returnjson = {'result':'created_success','urllist':urllist}
      return jsonify(returnjson)
  else:
    returnjson = {'result':'error','error':'参数不全'}
    return jsonify(returnjson)
Exemplo n.º 2
0
def create_mobile_ad_link():
  #默认跟踪参数的含义,见文档 https://github.com/white-shiro-bai/ghost_sa/blob/master/docs/admaster.md
  if 'src' in request.form and 'project' in request.form:
    src = request.form.get('src')
    expired_at = int(time.mktime(time.strptime(request.form.get('expired_at','2038-01-19'), "%Y-%m-%d"))) if 'expired_at' in request.form else 2147483647
    project = request.form.get('project',None)
    submitter = request.form.get('submitter',None)
    utm_source = request.form.get('utm_source',None)
    utm_medium = request.form.get('utm_medium',None)
    utm_campaign = request.form.get('utm_campaign',None)
    utm_content = request.form.get('utm_content',None)
    utm_term = request.form.get('utm_term',None)
    url_addon = encode_urlutm(utm_source=utm_source,utm_medium=utm_medium,utm_campaign=utm_campaign,utm_content=utm_content,utm_term=utm_term)
    result,count = read_mobile_ad_src_list(add_on_where="where `src`='"+src+"'")
    if count >0:
      src_args = result[0][2]
      url = '/cb/installation_track?'+src_args+'&project='+project+'&src='+src+'&'+url_addon
      urllist,urlstatus = check_mobile_ad_url(url=url)
      if urlstatus == 'exist':
        returnjson = {'result':urlstatus,'urllist':urllist}
        return jsonify(returnjson)
      else:
        if project:
          insert_result,insert_count = insert_mobile_ad_list(project=project,url=url,src=src,src_url=src_args,submitter=submitter,utm_source=utm_source,utm_medium=utm_medium,utm_campaign=utm_campaign,utm_content=utm_content,utm_term=utm_term,expired_at=expired_at)
          if insert_count == 0 :
            return jsonify({'result':'error','urllist':'url:'+url+'插入失败'})
          else :
            urllist,urlstatus = check_mobile_ad_url(url=url)
            returnjson = {'result':'created_success','urllist':urllist}
            return jsonify(returnjson)
        else:
          returnjson = {'result':'error','error':'参数不全'}
          return jsonify(returnjson)
    else:
      returnjson = {'result':'error','error':'暂不支持该源'}
      return jsonify(returnjson)
  else:
    returnjson = {'result':'error','error':'参数不全'}
    return jsonify(returnjson)