def deserialize(json): ##{ obj_lvl1 = jsload(json) tmp = jsload(jsload(obj_lvl1.get("data", "{}"))) if not isinstance(tmp, dict): tmp = {} return tmp
def deserialize(json):##{ obj_lvl1 = jsload(json) tmp = jsload(jsload(obj_lvl1.get("data", "{}"))) if not isinstance(tmp, dict): tmp = {} return tmp
def chat_handshake(ws): ##{ hello_msg = """{"event":"pusher:subscribe","data":{"channel":"%s"}}""" % CHANNEL ws.recv() ws.send(hello_msg) subscribe_status = ws.recv() return jsload(subscribe_status)
def return_twitter_connection(): with open('secrets.json', 'r') as s: secrets = jsload(s) return twitter.Api(consumer_key=secrets['consumer_key'], consumer_secret=secrets['consumer_secret'], access_token_key=secrets['access_token'], access_token_secret=secrets['access_token_secret'])
def chat_handshake(ws):##{ hello_msg = """{"event":"pusher:subscribe","data":{"channel":"%s"}}"""% CHANNEL ws.recv() ws.send(hello_msg) subscribe_status = ws.recv() return jsload(subscribe_status)
def load_cfg(): # load local info global local_info if local_info_path.exists(): with open(local_info_path, 'r') as local_info_file: local_info = jsload(local_info_file) else: local_info_path.touch() with open(local_info_path, 'w') as local_info_file: jsdump(local_info, local_info_file) # load pack settings global pack_settings if not pack_settings_path.exists(): print('Could not locate "{}", aborting...'.format(pack_settings_path)) exit() with open(pack_settings_path, 'r') as psfile: pack_settings = jsload(psfile)
def lambda_handler(event, context): message = jsload(event['body'])['message'] chat_id = message['chat']['id'] sticker_file_id = None message_id = 0 if 'sticker' in message.keys(): sticker_file_id = message['sticker']['file_id'] message_id = message['message_id'] if ('reply_to_message' in message.keys() and 'sticker' in message['reply_to_message'].keys()): sticker_file_id = message['reply_to_message']['sticker']['file_id'] message_id = message['reply_to_message']['message_id'] if sticker_file_id is not None: send_chat_action(chat_id,'upload_photo') send_image(chat_id,message_id,sticker_file_id) return { 'statusCode': 200, 'body': '' }
def tradingviewx(transport): ##{ buffer = ByteBuffer() xhr = next(transport) while True: try: data = xhr.raw.read(XHR_READ_SIZE) except Exception: xhr = next(transport) continue buffer.write(data) line = buffer.read_until(b"\r\n", consume=True) if not line: continue if line == ": -1": continue if line.startswith("data: "): line = line[6:] try: pkg = jsload(line) except Exception: continue channel = pkg.get("text", {}).get("channel") if channel != "chat_bitcoin": continue content = pkg.get("text").get("content") login = content.get('username') msg = content.get("text", "").encode("utf-8", errors="replace") meta = content.get("meta", {}) url = meta.get("url", "").encode("utf-8", errors="replace") if url: msg = "{}\n{:<19}{}{}{}".format(msg, "", COLOR_10, url, COLOR_0) if not msg: continue yield (login, msg)
def tradingviewx(transport):##{ buffer = ByteBuffer() xhr = next(transport) while True: try: data = xhr.raw.read(XHR_READ_SIZE) except Exception: xhr = next(transport) continue buffer.write(data) line = buffer.read_until(b"\r\n", consume=True) if not line: continue if line == ": -1": continue if line.startswith("data: "): line = line[6:] try: pkg = jsload(line) except Exception: continue channel = pkg.get("text", {}).get("channel") if channel != "chat_bitcoin": continue content = pkg.get("text").get("content") login = content.get('username') msg = content.get("text", "").encode("utf-8", errors="replace") meta = content.get("meta", {}) url = meta.get("url", "").encode("utf-8", errors="replace") if url: msg = "{}\n{:<19}{}{}{}".format(msg, "", COLOR_10, url, COLOR_0) if not msg: continue yield(login, msg)
from time import sleep from telepotpro import Bot from telepotpro.exception import TelegramError, BotWasBlockedError from json import load as jsload from os.path import abspath, dirname, join from stem import Signal from stem.control import Controller from modules import parsers from modules.crypter import decrypt_password from modules.database import User, Data, ParsedData with open(join(dirname(abspath(__file__)), "../settings.json")) as settings_file: js_settings = jsload(settings_file) maxMessageLength = 4096 adminIds = js_settings["admins"] bot = Bot(js_settings["token"]) def renewProxy(): if js_settings["useProxy"]: with Controller.from_port( address=js_settings["torProxyIP"], port=js_settings["torControlPort"]) as controller: controller.authenticate(password=js_settings["torControlPassword"]) controller.signal(Signal.NEWNYM) def getProxy():
def load_automata(): """loads all automata""" with open("arenbels/data/json/automata.json", "r", encoding="utf-8-sig") as read_file: dict_ata = jsload(read_file,object_hook=create_automaton_hook) return dict_ata
import pygame from random import randint from math import degrees, atan, tan, sqrt from json import dump as jsdump from json import load as jsload pygame.init() screen = pygame.display.set_mode((1280, 720)) with open('./bin/config.json') as json_file: config_data = jsload(json_file) newdata = config_data # the setting what needs when new game def default_setup(): global x global y global x_2 global y_2 global enemy_x global enemy_y global x_poison global y_poison global esc global xs global ys global space global bullet global alive global mov_speed
def main(): cnf = jsload(open(os.path.abspath('../etc/feed.json')).read()) logger = init_logger(cnf['LOG_PATH'], logging.INFO) feed.get_torrents(cnf)
def main(): cnf = jsload(open(os.path.abspath('../etc/rssget.json')).read()) logger = init_logger(cnf['LOG_PATH'], logging.INFO) rssget.run_feeds(cnf)
def define_controls(self) : "Parses controls_mapbuilder.json and puts it into self.ctrls dictionnary " with open("controls_mapbuilder.json", "r", encoding="utf8") as data : self.ctrls = jsload(data)
# Change this parameter if the file path is different BASE = "/app/app/irsystem/controllers/" auto_complete_list = pload( open(os.path.join(BASE, 'autocomplete_bigram_vocab.pickle'), 'rb')) project_name = "Informd" net_id = "Edward Mei: ezm4, Evan Pike: dep78, Lucas Van Bramer: ljv32, Sidd Srinivasan: ss2969, Wes Gurnee: rwg97" ########## change back for docker ################### BASE = "/app/app/irsystem/models/" reu_tf_idf_npz = open(os.path.join(BASE, 'reuters/tfidf_mat.npz')) reu_tf_idf_npz = load_npz(reu_tf_idf_npz) reu_ix_to_val = open(os.path.join(BASE, 'reuters/matrix_ix_to_val.json')) reu_ix_to_val = jsload(reu_ix_to_val) id_to_reu = open(os.path.join(BASE, 'reuters/id_to_reu_headline.csv')) id_to_reu = read_csv(id_to_reu) reu_vocab_to_ix = open(os.path.join(BASE, 'reuters/vocab_to_ix.json')) reu_vocab_to_ix = jsload(reu_vocab_to_ix) red_vocab_to_ix = open(os.path.join(BASE, 'reddit/vocab_to_ix.json')) red_vocab_to_ix = jsload(red_vocab_to_ix) words_compressed = open(os.path.join(BASE, 'u.npy'), 'rb') words_compressed = npload(words_compressed) docs_compressed = open(os.path.join(BASE, 'v_trans.npy'), 'rb') docs_compressed = npload(docs_compressed)
for col, col_name in enumerate(data_inputs['all_heads']): data[col_name] = np_records[:, col] return data # Data analyze def data_analyze_from_police(data): assert data is not None data_wrap_daily_increase = data['日增长率'].str.strip('%').astype(float) print('日增长率缺失总天数:', sum(np.isnan(data_wrap_daily_increase))) print('日增长率>0的天数:', sum(data_wrap_daily_increase > 0)) # Main Func if __name__ == "__main__": with open('./config/config.json') as config_file: config_params = jsload(fp=config_file) data = fetch_fund_data( fund_params=config_params['fund_get_params'], code=config_params['fund_code_list']['zhongou_shidaixianfeng']) # printout all the data print('data:', data) # printout the data by police data_analyze_from_police(data) drawing_module.draw_figure(data) # for debug, highlight the data #print(data)