def updateJournal(entry, needsBuilding=True, path=getJournalPath(), overwrite=False, alias='', ignoreURL=False): if needsBuilding: entry = buildJournalEntry(entry, ignoreURL) if (GitFileExists(path)): file = repo.get_contents(path, ref=GitHubBranch) # Get file from Branch if (overwrite): #print(getPageTitle(path)) data = "---\ntitle: " + getPageTitle( path) + "\nalias: " + alias + "\n---\n\n" #print(data) else: data = file.decoded_content.decode("utf-8") # Get raw string data data += (entry).strip() + "\n" push(path, git_messages['COMMIT_MESSAGE'].format(BotName, getTimestamp()), data, GitHubBranch, update=True) else: data = "---\ntitle: " + getPageTitle( path) + "\nalias: " + alias + "\n---\n\n" + (entry).strip() + "\n" push(path, git_messages['COMMIT_MESSAGE'].format(BotName, getTimestamp()), data, GitHubBranch, update=False)
def createAsset(token, assetId, googleDocsURL, label, extension): import base64 "we are going to use tagging to track metadata such as the number of entries" # perform validation tokens = DDBCache(os.environ['TOKENS_TABLE_NAME']) assets = DDBCache(os.environ['ASSETS_TABLE_NAME']) users = DDBCache(os.environ['USERS_TABLE_NAME']) if token not in tokens: return {'message': 'invalid token'} userId = tokens[token]['userId'] user = users[userId] if assetId == None: # TODO transact if user['file_count'] >= user['file_limit']: return {'message': 'reached file limit'} user['file_count'] += 1 assetId = utils.genHash(token) + '.' + extension while assetId in assets: # we have a conflict reroll assetId = utils.genHash(token) format_tuple = (urllib.parse.quote_plus( os.environ['ASSETS_BUCKET_NAME']), urllib.parse.quote_plus(userId), urllib.parse.quote_plus(assetId)) s3Path = 'https://s3.amazonaws.com/%s/%s/%s' % format_tuple asset = { "assetId": assetId, "userId": user['userId'], "dateModified": utils.getTimestamp(), "googleDocsURL": googleDocsURL, "label": label, "version": 1, "s3Path": s3Path } else: asset = assets[assetId] asset['dateModified'] = utils.getTimestamp() asset['version'] += 1 s3Key = '%s/%s' % (asset['userId'], asset['assetId']) # could also have conflict later on, but we can play it by ear # TODO transactional # begin to upload the file to s3 download_file_from_google_drive(googleDocsURL, s3Key) users[userId] = user assets[assetId] = asset return {'message': 'success'}
def __init__(self, sender): self.sender = sender self.key = key self.send_to = [] self.timestamp = utils.getTimestamp() self.tip = 0
def decryptGraph(): contents = repo.get_contents("") while contents: content = contents.pop(0) if '/assets/' not in content.url and '/logseq/' not in content.url: if content.type == "dir": contents.extend(repo.get_contents(content.path)) else: gitFileContent = getGitFileContent(content) if gitFileContent: print("decrypting " + content.path) try: push(content.path, git_messages['COMMIT_MESSAGE'].format( BotName, utils.getTimestamp()), gitFileContent, GitHubBranch, update=True) except: print("***********" + content.path + "*******************") # print(content.path) print("*********** All Files Encrypted *******************") config.setGraphAgeEncrypted('false')
def switchTheme(cssFile): cssContent = getGitFileContent(cssFile) push('logseq/custom.css', git_messages['COMMIT_MESSAGE'].format(BotName, utils.getTimestamp()), cssContent, GitHubBranch, update=True)
def updateAsset(data, fileType): print('u') path = assetsFolder + "/" + getTimestamp(True) + "." + fileType print(config.getAssetsDestination()) if (config.getAssetsDestination() == 'github'): update = False if (GitFileExists(path)): update = True push(path, git_messages['COMMIT_MESSAGE'].format(BotName, getTimestamp()), data, GitHubBranch, update=update) path = ("![](./" + path + ")") elif (config.getAssetsDestination() == 'firebase'): path = ("![](" + UploadToFirebase(data, path) + ")") return path
def updateCalendarsFile(): path = "pages/" + config.getcalendarFile() contents = getGitFileContent(path, True) contents = utils.generateCalendarsFile(contents) push(path, git_messages['COMMIT_MESSAGE'].format(BotName, utils.getTimestamp()), contents, GitHubBranch, update=True)
def __init__(self, miner, prev_block=None): self.miner = miner self.prev_block = prev_block try: self.prev_hash = prev_hash.merkle_tree[1] except: self.prev_hash = b'\x00' self.transactions = [] self.timestamp = utils.getTimestamp()
def stepSimulator(self): current_time = datetime.datetime.now() elapsed = current_time - self.prev_time self.sim_time += elapsed * self.sim_factor msg = Clock() msg.clock = rospy.Time.from_sec(getTimestamp(self.sim_time)) self.clock_pub.publish(msg) self.prev_time = current_time if self.sim_time > self.future_roms.date: print "ROMS Rollover" #Increment Simulator self.past_roms = self.future_roms self.future_roms = ROMSSnapshot(self.past_roms.idx + 1, self.roms_dates, self.roms_files)
def doWork(self): try: debugRequest = debug.debugRouter(self, listOfLogs) if debugRequest == True: return except Exception as e: utils.printStackTrace(e) logEntry = LogEntry(utils.getTimestamp(), self.path, self.request, None, None) try: path = self.path path = path.replace("/Main", "") path = path.replace("/", "") folderExists = utils.getDirectories_Match(path) if folderExists == True: pathPattern = "./" + path + "/*" fileObject = utils.getFiles_LatestModified(pathPattern) self.send_response(200) self.send_header('Content-Type', "text/xml; charset=UTF-8") self.end_headers() logEntry.filePath = fileObject with open(fileObject, 'rb') as file: self.wfile.write( file.read()) # Read the file and send the contents with open(fileObject, 'rb') as file: logEntry.response = file.read() addLog(self, logEntry) else: self.send_response(404) self.send_EmptyResponse() addLog(self, logEntry) except Exception as e: utils.printStackTrace(e) self.send_response(500) self.send_EmptyResponse() addLog(self, logEntry)
def credentialRequest(self, request): myPrint("addApplication api called") url = '%s/v1/credentialrequest/requestgenerator' % self.server cookies = {'Authorization': self.token} ts = getTimestamp() j = { "id": "mosip.credentialrequest", "request": request, "requesttime": ts, "version": "1.0" } if conf.debug: myPrint("Request: " + dictToJson(j)) r = requests.post(url, cookies=cookies, json=j, verify=self.ssl_verify) resp = self.parseResponse(r) if conf.debug: myPrint("Response: " + dictToJson(resp)) return resp
def retrieveAsset(assetId, identity, params): "we are going to use tagging to track metadata such as the number of entries" # perform validation assets = DDBCache(os.environ['ASSETS_TABLE_NAME']) if assetId not in assets: # let's log failures too timeseries = DDBCache(os.environ['TIMESERIES_TABLE_NAME'], RangeKey='failures') timeseries[timestamp] = identity return {'message': 'asset not found', 'success': False} timeseries = DDBCache(os.environ['TIMESERIES_TABLE_NAME'], RangeKey=assetId) timestamp = utils.getTimestamp() timeseries[timestamp] = {**identity, **params} asset = assets[assetId] return {'Location': asset['s3Path'], 'success': True}
def authGetToken(self, appid, username, pwd): myPrint("authenticate api called") url = '%s/v1/authmanager/authenticate/clientidsecretkey' % self.server ts = getTimestamp() j = { "id": "mosip.io.clientId.pwd", "metadata": {}, "version": "1.0", "requesttime": ts, "request": { "appId": appid, "clientId": username, "secretKey": pwd } } if conf.debug: myPrint("Request: " + dictToJson(j)) r = requests.post(url, json=j, verify=self.ssl_verify) resp = self.parseResponse(r) if conf.debug: myPrint("Response: " + dictToJson(resp)) token = readToken(r) return token
def __init__(self): print "Loading ROMS Data....." start_date = rospy.get_param('start_date') start_date = datetime.datetime.strptime(start_date, '%Y/%m/%d') end_date = rospy.get_param('end_date') end_date = datetime.datetime.strptime(end_date, '%Y/%m/%d') #roms_files is an ordered list of ROMS NETCDF files containing simulated data #The actual files containing data get located in the /data folder # self.roms_data = {} self.roms_dates, self.roms_files = getROMS(start_date, end_date) self.past_roms = ROMSSnapshot(0, self.roms_dates, self.roms_files) self.future_roms = ROMSSnapshot(1, self.roms_dates, self.roms_files) dataset = nc.Dataset(self.roms_files[0]) self.roms_lat = dataset['lat'][:] self.roms_lon = np.array( [x if x < 180. else x - 360 for x in dataset['lon'][:]]) self.depth = dataset['depth'][:] print self.depth print len(self.roms_lat) print len(self.roms_lon) print len(self.depth) roms_n_bound = np.max(self.roms_lat) roms_s_bound = np.min(self.roms_lat) roms_e_bound = np.max(self.roms_lon) roms_w_bound = np.min(self.roms_lon) self.max_depth = np.max(self.depth) # for dt, file_path in zip(self.roms_dates, roms_files): # self.roms_data[dt] = nc.Dataset(file_path) print "Loading ROMS Data Complete" print "Loading Bathymetry Data......" bathymetry_file = getBathymetry(roms_n_bound, roms_s_bound, roms_e_bound, roms_w_bound) dataset = nc.Dataset(bathymetry_file) self.bathymetry_lat = dataset['lat'] self.bathymetry_lon = dataset['lon'] self.bathymetry = dataset['Band1'] self.bathymetry_n_bound = np.max(self.bathymetry_lat) self.bathymetry_s_bound = np.min(self.bathymetry_lat) self.bathymetry_e_bound = np.max(self.bathymetry_lon) self.bathymetry_w_bound = np.min(self.bathymetry_lon) print "Loading Bathymetry Data Complete" self.sim_factor = rospy.get_param('sim_speedup_factor') print "Beginning Simulation with sim factor:", self.sim_factor # print "ROMS Bounds:" # print "\tNorth", roms_n_bound, "deg Lat" # print "\tSouth", roms_s_bound, "deg Lat" # print "\tEast", roms_e_bound, "deg Lon" # print "\tWest", roms_w_bound, "deg Lon" # print "Bathymetry Bounds:" # print "\tNorth", bathymetry_n_bound, "deg Lat" # print "\tSouth", bathymetry_s_bound, "deg Lat" # print "\tEast", bathymetry_e_bound, "deg Lon" # print "\tWest", bathymetry_w_bound, "deg Lon" self.n_bound = min(self.bathymetry_n_bound, roms_n_bound) self.s_bound = max(self.bathymetry_s_bound, roms_s_bound) self.e_bound = min(self.bathymetry_e_bound, roms_e_bound) self.w_bound = max(self.bathymetry_w_bound, roms_w_bound) print "Simulation Bounds:" print "\tNorth", self.n_bound, "deg Lat" print "\tSouth", self.s_bound, "deg Lat" print "\tEast", self.e_bound, "deg Lon" print "\tWest", self.w_bound, "deg Lon" rospy.set_param('sim_n_bound', float(self.n_bound)) rospy.set_param('sim_s_bound', float(self.s_bound)) rospy.set_param('sim_e_bound', float(self.e_bound)) rospy.set_param('sim_w_bound', float(self.w_bound)) print "Initializing Publishers and Services" self.clock_pub = rospy.Publisher("/clock", Clock, queue_size=1) rospy.Service(rospy.get_param("world_sim_topic"), SimQuery, self.simQueryHandle) rospy.Service('WorldSnapshot', SimSnapshot, self.simSnapshotHandle) self.sim_time = self.roms_dates[ 0] #Initialize simulated clock with beginning of ROMS Data self.prev_time = datetime.datetime.now() msg = Clock() msg.clock = rospy.Time.from_sec(getTimestamp(self.sim_time)) self.clock_pub.publish(msg)
def updateJournal(entry, needsBuilding=True, path=None, overwrite=False, alias='', ignoreURL=False, isJournalFile=True): if path == None: path = utils.getJournalPath() if needsBuilding: entry = buildJournalEntry(entry, ignoreURL) if (GitFileExists(path)): file = repo.get_contents(path, ref=GitHubBranch) # Get file from Branch if (overwrite): data = "---\ntitle: " + utils.getPageTitle( path) + "\nalias: " + alias + "\n---\n\n" else: data = file.decoded_content.decode("utf-8") # Get raw string data if (config.isGraphAgeEncrypted()): if AgeEncHandler.isAgeEncrypted( data ) == 1: # encrypted but without \n requires transformation data = (AgeEncHandler.ageDecrypt( AgeEncHandler.convertToAgeString(data))) elif AgeEncHandler.isAgeEncrypted( data) == 2: # encrypted no transformation required data = (AgeEncHandler.ageDecrypt(data)) data += (entry).strip() + "\n" if (config.isGraphAgeEncrypted()): data = AgeEncHandler.ageEncrypt(data) push(path, git_messages['COMMIT_MESSAGE'].format(BotName, utils.getTimestamp()), data, GitHubBranch, update=True) else: if isJournalFile: journalTemplate = config.journalTemplate if journalTemplate: data = "---\ntitle: " + utils.getJournalTitle( ) + "\n---\n\n" + journalTemplate + (entry).strip() + "\n" else: data = "---\ntitle: " + utils.getJournalTitle( ) + "\n---\n\n" + (entry).strip() + "\n" else: data = "---\ntitle: " + utils.getPageTitle( path) + "\nalias: " + alias + "\n---\n\n" + ( entry).strip() + "\n" if (config.isGraphAgeEncrypted()): data = AgeEncHandler.ageEncrypt(data) push(path, git_messages['COMMIT_MESSAGE'].format(BotName, utils.getTimestamp()), data, GitHubBranch, update=False)