async def verify(self, ctx, passcode): """Gain access to some of the owner-only commands! Parameters: passcode - The passcode. Every time an user is verified, a new one is generated.""" with open("../DSB_Files/ultra_secret_passcode.txt", "r") as file: passkey = file.read() if passcode != passkey: await say(ctx, ":interrobang: - Passcodes do not match!") elif passcode == passkey: verified_users.append(ctx.author.id) list_keychars = [] for i in range(20): list_choice = [] x = random.randint(65, 90) list_choice.append(x) y = random.randint(97, 122) list_choice.append(y) z = random.randint(48, 57) list_choice.append(z) chooser = random.choice(list_choice) converted = chr(chooser) list_keychars.append(str(converted)) passcode = "".join(list_keychars) print("The new password is: " + passcode) fs.write("../DSB_Files/ultra_secret_passcode.txt", passcode) await say(ctx, ":white_check_mark: - Successfully validated!")
def test_write(): write_content = "test content" fs.write(TEST_FILE, write_content) with open(TEST_FILE, 'r') as file: content = file.read() assert write_content == content
def make(): """Generate the current shell scripts from the templates""" clean() for _file in fs.find('*.sh', SRC_DIR): tplname = _file.replace(SRC_DIR + '/', "") dest = fs.join(DIST_DIR, fs.filename(tplname)) tpl = env.get_template(tplname) fs.write(dest, tpl.render()) print("Writing template %s" % tplname)
def test_write_utf8(): write_content = """"this is a test content with utf-8 characters, such as ÀÁÂÂÄ or ¼½¾""" fs.write(TEST_FILE, write_content) with open(TEST_FILE, 'rb') as file: content = file.read() assert write_content == content.decode('UTF-8')
def add_model_to_report(model, params): timestamp = params.get('timestamp') shp = params.get('input_shape', (3, 112, 112)) batchsize = params.get('batchsize', 64) # Write model structure as JSON file fs.write('results/%s/model.json' % timestamp, model.to_json()) # Print the model Shape add_to_report('\n## Model architecture') model.summary() m_def = get_model_summary(model) print('\nUsing architecture:') print(m_def) # Write model dimensions to Report add_to_report(m_def, params)
def main(): fs.init('fs') fs.mkdir('a') fs.mkdir('b') fs.mkdir('a/c') fs.create('a/d.txt', 20) fs.create('a/c/e.txt', 20) fd1 = fs.open('a/d.txt', 'rw') fd2 = fs.open('a/c/e.txt', 'rw') fs.write(fd1, 'hello\nbye\n') fs.write(fd2, 'goodbye\n') print fs.read(fd2, 4) print fs.readlines(fd1) for f in fs.readlines(fd1): print(f), fs.close(fd1) fs.close(fd2) fs.suspend()
async def on_ready(): print("Ready to go!") await bot.change_presence(activity=discord.Game(name="| D.help |")) list_keychars = [] for i in range(20): list_choice = [] x = random.randint(65, 90) list_choice.append(x) y = random.randint(97, 122) list_choice.append(y) z = random.randint(48, 57) list_choice.append(z) chooser = random.choice(list_choice) converted = chr(chooser) list_keychars.append(str(converted)) passcode = "".join(list_keychars) print("The password is: " + passcode) fs.write("../DSB_Files/ultra_secret_passcode.txt", passcode)
async def setlog(self, ctx, channel: discord.TextChannel = None): """Sets the log channel. Parameters: channel - The channel used for the logs. The channel has to be mentioned normally and the bot needs to be able to read and send to it. Permissions: Administrator""" if channel != None: fs.write(f"../DSB_Files/log_of_{ctx.guild.id}.txt", str(channel.id)) await say(ctx, ":white_check_mark: - Log Channel set!") else: if fs.exists(f"../DSB_Files/log_of_{ctx.guild.id}.txt"): os.remove(f"../DSB_Files/log_of_{ctx.guild.id}.txt") await say( ctx, ":white_check_mark: - Log channel deleted out of memory!") else: await say(ctx, ":interrobang: - Please mention a channel!")
import pypandoc import os import fs # Read the markdown README doc = pypandoc.convert('README.md', 'rst') # Write a rST README for long_description fs.write('README.txt', doc) # Run the register command os.system("python setup.py register sdist upload") # Remove the rST README fs.rm('README.txt')
a = Term(arr[0]) b = Term(arr[1]) print(a) print(b) print(a - b) print(abs((a - b).solve())) return input if __name__ == '__main__': #IN_NAME = 'B-small-attempt2.in' IN_NAME = 'input.txt' OUT_NAME = 'output.txt' raw_input = fs.read(IN_NAME) print('====> Reading %s' % IN_NAME) rows = raw_input.split('\n') cases = int(rows[0]) solution = '' for i, row in enumerate(rows): # Skip first row (contains number of entries) if i == 0: continue # Skip last row (contains only \n) if i == len(rows) - 1: continue solution += 'Case #%i: %s\n' % (i, str(solve(row))) fs.write(OUT_NAME, solution) print('====> Writing %s' % OUT_NAME)
b = Term(arr[1]) print(a) print(b) print(a - b) print(abs((a - b).solve())) return input if __name__ == '__main__': #IN_NAME = 'B-small-attempt2.in' IN_NAME = 'input.txt' OUT_NAME = 'output.txt' raw_input = fs.read(IN_NAME) print('====> Reading %s' % IN_NAME) rows = raw_input.split('\n') cases = int(rows[0]) solution = '' for i, row in enumerate(rows): # Skip first row (contains number of entries) if i == 0: continue # Skip last row (contains only \n) if i == len(rows) - 1: continue solution += 'Case #%i: %s\n' % (i, str(solve(row))) fs.write(OUT_NAME, solution) print('====> Writing %s' % OUT_NAME)
import pandoc import os import fs pandoc.core.PANDOC_PATH = '/usr/bin/pandoc' # Create New Pandoc Document doc = pandoc.Document() # Read the markdown README doc.markdown = fs.read('README.md') # Write a rST README for long_description fs.write('README.txt', doc.rst) # Run the register command os.system("python setup.py register sdist upload") # Remove the rST README fs.rm('README.txt')
if vc.isOpened(): # try to get the first frame rval, frame = vc.read() else: rval = False while rval: cv2.imshow("preview", frame) cv2.imwrite('./imgCaptured.png', frame) rval, frame = vc.read() key = cv2.waitKey(20) if key == 27: # exit on ESC break cv2.destroyWindow("preview") app = ClarifaiApp(api_key='444fb551757f45e0b124892399e5b760') model = app.models.get('general-v1.3') image = ClImage(file_obj=open('./imgCaptured.png', 'rb')) content = json.dumps(model.predict([image])) strings = json.loads(content) imageText = "There is a " + strings["outputs"][0]["data"]["concepts"][0][ "name"] + " ahead!" print(imageText) fs = open("textToSpeech.txt", "w") fs.write(imageText) fs.close()
fs.chdir('a') fs.mkdir('b2') fs.mkdir('/a/b3') #now on drectory b3 fs.chdir('b3') fs.mkdir('/a/b1/c1') print fs.listdir('/a/b1') fs.create('/a/b3/fc', 30) fcd = fs.open('/a/b3/fc', 'w') fs.write(fcd, '\nnow we needtousegitagain\n') fs.close(fcd) fcd1 = fs.open('/a/b3/fc', 'r') print fs.readlines(fcd1) print fs.read(fcd1, 5) fs.seek(fcd1, 5) print fs.read(fcd1, 10) fs.close(fcd1) fs.suspend() #fs.open('/fa','r') fs.chdir('..') #resume is not sure fs.resume('abc.fssave') fs.create('fb', 29) fbd = fs.open('fb', 'w') fs.write(fbd, 'quizz is so annoying.\n')
print e fs.listdir() fs.listdir('a1') try: fs.deldir('c1') except Exception, e: print e fs.getcwd() fd = fs.open('a1/a2.txt', 'r') try: fd2 = fs.open('a1/b.txt', 'r') except Exception, e: print e try: fs.write(fd, 'hello\n') except Exception, e: print e try: fs.write(fd + 1, 'hello\n') except Exception, e: print e fd3 = fs.open('/a0/a1/a2.txt', 'w') print fd == fd3 fs.write(fd, 'hello\n') print fs.read(fd, 6) fs.seek(fd, 0) print fs.read(fd, 6) try: fs.seek(fd, 7) except Exception, e:
print("Expected Shape: ", nb_filter, stack_size, nb_col, nb_row) print("Found Shape: ", np.array(blobs[0].data).shape) weights_p = blobs[0].data.astype(dtype=np.float32) weights_b = blobs[1].data.astype(dtype=np.float32) if len(weights_p.shape) > 2: # Caffe uses the shape f, (d, y, x) # ConvnetJS uses the shape f, (y, x, d) weights_p = np.swapaxes(np.swapaxes(weights_p, 3, 1), 2, 1) print("Converted to Shape: ", weights_p.shape) weights = { 'filter': weights_p.reshape((nb_filter, stack_size*nb_col*nb_row)).tolist(), 'bias': weights_b.tolist() } filename = WEIGHTS_DIR + key + '.txt' if not fs.exists(fs.dirname(filename)): fs.mkdir(fs.dirname(filename)) fs.write(fs.add_suffix(filename, "_filter"), "") for i, f_weights in enumerate(weights['filter']): if i == len(weights['filter']) - 1: fs.append(fs.add_suffix(filename, "_filter"), ",".join(map(str, f_weights))) else: fs.append(fs.add_suffix(filename, "_filter"), ",".join(map(str, f_weights)) + "\n") fs.write(fs.add_suffix(filename, "_bias"), ",".join(map(str, weights['bias'])))
from __future__ import print_function import fs import numpy as np # Make sure that caffe and pycaffe are installed # and on the python path: caffe_root = '../caffe/' # this file is expected to be in {caffe_root}/examples import sys sys.path.insert(0, caffe_root + 'python') import caffe if len(sys.argv) != 3: print("Usage: python convert_protomean.py data/ilsvrc12/imagenet_mean.binaryproto data/ilsvrc12/imagenet_mean.txt") sys.exit() blob = caffe.proto.caffe_pb2.BlobProto() data = open( sys.argv[1] , 'rb' ).read() blob.ParseFromString(data) arr = np.array( caffe.io.blobproto_to_array(blob) ) s = np.shape(arr[0]) out = arr[0].reshape((3,s[1]*s[2])).tolist() fs.write( sys.argv[2] , "\n".join(map(lambda o: ",".join(map(str, o)), out)) )