Skip to content

Instantly share code, notes, and snippets.

@aclisp
Last active October 4, 2021 15:42
Show Gist options
  • Select an option

  • Save aclisp/691e8d58d6ee6b133f6bc23b16ce0ddd to your computer and use it in GitHub Desktop.

Select an option

Save aclisp/691e8d58d6ee6b133f6bc23b16ce0ddd to your computer and use it in GitHub Desktop.

Revisions

  1. aclisp revised this gist May 28, 2019. 1 changed file with 36 additions and 0 deletions.
    36 changes: 36 additions & 0 deletions test-http-api.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    headers = {
    'Content-Type': 'application/json',
    }
    params = {'hashkey': '116093411'}
    request = {
    "context":"",
    "ts":1558940296307,
    "user": {"uid":116093411,
    "hdid":"18ba516ab9fab34c7294a15a0303fc2a7c84b364",
    "sex":1,
    "age":26,
    "os":"ios",
    "region":"CN",
    "lan":"zh"},
    "gameid":"ktv",
    "num": 1,
    "offset":0,
    "app_version": "2.5.8",
    "excludes":[]
    }
    request = json.dumps(request)
    response = requests.post('http://rec-863.ihago.net/recomm/hago/room_random_recom', headers=headers, params=params, data=request)
    res = json.loads(response.text)
    print('res ===>', res)
    rid = res['results'][0]['rid']

    print('status ===> ', ymicro_api(url_api_863, 'net.ihago.room.srv.rmgr', 'RoomMgr.GetStatus', {
    'ids': [rid]
    }))
    print('info ===>', ymicro_api(url_api_863, 'net.ihago.room.srv.rmgr', 'RoomMgr.GetInfos', {
    'ids': [rid]
    }))

    key = 'rm_rm_' + rid
    cli = redis_cli(6, key)
    cli.hgetall(key)
  2. aclisp revised this gist May 28, 2019. 1 changed file with 20 additions and 0 deletions.
    20 changes: 20 additions & 0 deletions ymicro-example.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    # YMICRO UTILITIES

    url_api_863 = 'http://api-inner-863.ihago.net/ymicro/api'

    def ymicro_api(url, service_name, method_name, request):
    headers = {
    'Content-Type': 'application/json',
    'X-Ymicro-Api-Service-Name': service_name,
    'X-Ymicro-Api-Method-Name': method_name,
    }
    if isinstance(request, dict):
    request = json.dumps(request)
    response = requests.post(url, headers=headers, data=request)
    return json.loads(response.text)

    # YMICRO EXAMPLES

    ymicro_api(url_api_863, 'net.ihago.room.srv.rmgr', 'RoomMgr.GetStatus', {
    'ids': ['P_153932504']
    })
  3. aclisp revised this gist May 28, 2019. 1 changed file with 39 additions and 0 deletions.
    39 changes: 39 additions & 0 deletions redis-example.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    import sys
    import os.path
    import configparser
    import mmh3
    import math
    import redis
    import time
    import requests
    import json

    # REDIS UTILITIES

    redis_conf_dir = '/data/services/common-conf/rs_ikxd_recomm_redis/conf'

    def redis_conf_file(cluster_no):
    return os.path.join(redis_conf_dir, 'cluster{}.redis.properties'.format(cluster_no))

    def redis_conf(cluster_no):
    with open(redis_conf_file(cluster_no), 'r') as f:
    config_string = '[default]\n' + f.read()
    config = configparser.ConfigParser()
    config.read_string(config_string)
    return config

    def redis_host(cluster_no, key):
    c = redis_conf(cluster_no)
    index = abs(mmh3.hash(key)) % c.getint('default', 'redis.host.num')
    return c.get('default', 'redis.{}.host'.format(index))

    def redis_cli(cluster_no, key):
    host_and_port = redis_host(cluster_no, key)
    host, port = host_and_port.split(':')
    return redis.Redis(host=host, port=port, db=0)

    # REDIS EXAMPLES

    key = 'ikxd_u_17179935728'
    cli = redis_cli(3, key)
    cli.hgetall(key)
  4. aclisp created this gist May 18, 2019.
    10 changes: 10 additions & 0 deletions setup-jupyter.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    $ sudo apt-get update
    $ sudo apt-get install python3-pip
    $ sudo python3 -m pip install --upgrade pip
    $ sudo python3 -m pip install --upgrade pyOpenSSL
    $ sudo python3 -m pip install --upgrade six requests
    $ sudo python3 -m pip install murmurhash3 redis PyMySQL pymongo pandas
    $ sudo python3 -m pip install jupyter
    $ sudo apt-get install jq
    $ cat /home/dspeak/yyms/hostinfo | jq '.ips'
    $ jupyter notebook --ip=x.x.x.x --port=12345