def scrape(ig_handles): username = ig_handles filename = "results" people = username.split(",") invalid_accounts = [] open('csvs/' + filename + '.csv', 'w').close() for person in people: if helpers.main(person.strip(), filename) == -1: invalid_accounts.append(str(person)) print str(person) + " is an invalid or private Instagram account." if len(invalid_accounts) > 0: return 0 else: return 1
job = helpers.wait_for_job(self._wp.start_job('pwd')) self.assertEqual(helpers.read_file(job.stdout_path), job.path + '\n') def test_env_inheritance(self): with helpers.update_env(TEST_VALUE='abc'): job = helpers.wait_for_job(self._wp.start_job('echo $TEST_VALUE')) self.assertEqual(helpers.read_file(job.stdout_path), 'abc\n') def test_default_shell_label(self): job = self._wp.start_job('echo "a b"') self.assertEqual(job.get_label(), 'echo "a b"') helpers.wait_for_job(job) def test_default_args_label(self): job = self._wp.start_job(['echo', 'a b']) self.assertEqual(job.get_label(), 'echo \'a b\'') helpers.wait_for_job(job) def test_custom_label(self): job = self._wp.start_job('true', label='my label') self.assertEqual(job.get_label(), 'my label') helpers.wait_for_job(job) def test_unicode_label(self): job = self._wp.start_job('true', label=u'\u0119\u0105') self.assertEqual(job.get_label(), u'\u0119\u0105') helpers.wait_for_job(job) if __name__ == '__main__': helpers.main()
def test_compute(): """Tests that the HardTanh layer correctly computes a HardTanh. """ inputs = np.random.uniform(size=(101, 1025)) true_hard_tanh = np.minimum(np.maximum(inputs, -1.0), 1.0) layer = HardTanhLayer() assert np.allclose(layer.compute(inputs), true_hard_tanh) torch_inputs = torch.FloatTensor(inputs) torch_outputs = layer.compute(torch_inputs).numpy() assert np.allclose(torch_outputs, torch_inputs) def test_serialize(): """Tests that the HardTanh layer correctly [de]serializes itself. """ serialized = HardTanhLayer().serialize() assert serialized.WhichOneof("layer_data") == "hard_tanh_data" deserialized = HardTanhLayer.deserialize(serialized) assert deserialized.serialize() == serialized serialized.relu_data.SetInParent() assert HardTanhLayer.deserialize(serialized) is None main(__name__, __file__)
self.authorized_extensions = printers + cnc + shopbot + omax + epilog_laser + metabeam + up def _print_log(self): ''' Print the logs related to the current file being processed ''' tmp_log = self.log_name.fields(**self.cur_file.log_details) if not self.cur_file.log_details.get('valid'): tmp_log.warning(self.cur_file.log_string) else: tmp_log.debug(self.cur_file.log_string) def processdir(self): ''' Main function doing the processing ''' for srcpath in self._list_all_files(self.src_root_dir): self.log_name.info('Processing {}', srcpath.replace(self.src_root_dir + '/', '')) self.cur_file = FilePier9(srcpath, srcpath.replace(self.src_root_dir, self.dst_root_dir)) if self.cur_file.extension in self.authorized_extensions: self.cur_file.add_log_details('valid', True) self.cur_file.log_string = 'Expected extension: ' + self.cur_file.extension self._safe_copy() else: self.cur_file.log_string = 'Bad extension: ' + self.cur_file.extension self._print_log() if __name__ == '__main__': main(KittenGroomerPier9)
# now we are going to our first code. def main(): print("Current Module Name:", __name__) if __name__ == "__main__": main() # now we can know why this code useful? # we can see if __name__=="__main__" # which pretty much saying, if this file ran directly by python, or it is imported in anyother file. # now lets add something in our main() function. import helpers # now if we do the same thing in the helpers and run that, # we can see it didn't execute the main() function of helpers in our current module # the reason it didnt print that line of main() function is because now we have this (if __name__) check inplace. # just to illustrate it further, we can go to helpers module and type in an else condition. import helpers # we can see that it is saying run from import as our else statement. # the reason we need to use this because sometimes ther might be code that we want to run that as main file. # sometimes there code that we will only run by impoting them. # another thing is why we are using the main() method, we can directly put the code in the if conditional to separate those. # we are creating a main method because we can also use that method by importing that module, # which we cant do with the conditional. helpers.main()
os.makedirs(path_captions, exist_ok=True) already_processed = os.listdir(path_captions) for video in videos: count += 1 print('==' * 20) print(f'getting {count} of {maxx} : {video["videoID"]}') print('==' * 20) videos_titles += f'{video["videoID"]}:{video["title"]}\n' if video["videoID"] + '.txt' in already_processed: print('Already processed. Skipping...') else: try: print(f'Video ID: {video["videoID"]}; Title: {video["title"]}') # print(f'Title using lib: {get_title_using_lib(video["videoID"])}') main(video["videoID"], translation=False, output_file= f'{os.path.join(path_captions, video["videoID"])}.txt') if not os.path.isfile( f'{os.path.join(path_captions, video["videoID"])}.txt' ): raise Exception('not_saved') except: failed_videos += f'failed to download: {video["videoID"]}\n' print(f'failed to download: {video["videoID"]}\n') with open(os.path.join(path, 'titles.txt'), 'w') as f: f.write(videos_titles) with open(os.path.join(path, 'fails.txt'), 'w') as f: f.write(failed_videos)
self.assertEqual(returncode, 150) self.assertEqual(log, []) self.assertEqual(self.sh_mocked_calls(), [ ("wait-for-root", "LABEL=some-label", "180"), ("panic", "unable to find root partition LABEL=some-label"), ]) def test_do_root_mounting__works(self) -> None: """Test do_root_mounting works when writable_label is set correctly.""" self.sh_inject("writable_label=some-label") self.sh_inject("writable_mnt=/fake-writable-mnt") self.sh_inject("ln -s /dev/null /dev/some-label") self.sh_mock("findfs", prints="/dev/zero") self.sh_mock("mount") self.sh_mock("modprobe") returncode, log = self.sh_run("do_root_mounting") self.assertEqual(returncode, 0) self.assertEqual(log, []) self.assertEqual(self.sh_mocked_calls(), [ ("wait-for-root", "LABEL=some-label", "180"), ("findfs", "LABEL=some-label"), ("modprobe", "squashfs"), ("wait-for-root", "LABEL=some-label", "180"), ("mount", "/dev/null", "/fake-writable-mnt"), ]) if __name__ == "__main__": # logging.basicConfig(level=logging.DEBUG) main()
def get_sheet(): if main(): return render_template("survived.html") else: return render_template("dead.html")
Main function doing the processing ''' if src_dir is None: src_dir = self.src_root_dir if dst_dir is None: dst_dir = self.dst_root_dir if self.recursive > 0: self._print_log() if self.recursive >= self.max_recursive: self.cur_log.warning('ARCHIVE BOMB.') self.cur_log.warning('The content of the archive contains recursively other archives.') self.cur_log.warning('This is a bad sign so the archive is not extracted to the destination key.') self._safe_rmtree(src_dir) if src_dir.endswith('_temp'): archbomb_path = src_dir[:-len('_temp')] self._safe_remove(archbomb_path) for srcpath in self._list_all_files(src_dir): self.cur_file = File(srcpath, srcpath.replace(src_dir, dst_dir)) self.log_name.info('Processing {} ({}/{})', srcpath.replace(src_dir + '/', ''), self.cur_file.main_type, self.cur_file.sub_type) self.mime_processing_options.get(self.cur_file.main_type, self.unknown)() if not self.cur_file.is_recursive: self._print_log() if __name__ == '__main__': main(KittenGroomer)