Last active
October 4, 2021 15:42
-
-
Save aclisp/691e8d58d6ee6b133f6bc23b16ce0ddd to your computer and use it in GitHub Desktop.
Install python3 jupyter notebook on Ubuntu 16.04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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'] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment