|
16 | 16 | def main(): |
17 | 17 | """Script entry point.""" |
18 | 18 |
|
19 | | - print('Fetching data from IMDb...') |
| 19 | + print("Fetching data from IMDb...") |
20 | 20 |
|
21 | | - with open('names.txt', 'w') as destination: |
| 21 | + with open("names.txt", "w") as destination: |
22 | 22 | destination.writelines(names()) |
23 | 23 |
|
24 | | - with open('names.txt') as source, \ |
25 | | - open('sorted_names.txt', 'w') as destination: |
| 24 | + with open("names.txt") as source, open( |
| 25 | + "sorted_names.txt", "w" |
| 26 | + ) as destination: |
26 | 27 | destination.writelines(sorted(source.readlines())) |
27 | 28 |
|
28 | 29 | print('Created "names.txt" and "sorted_names.txt"') |
29 | 30 |
|
30 | 31 |
|
31 | 32 | def names(): |
32 | 33 | """Return a generator of names with a trailing newline.""" |
33 | | - url = 'https://datasets.imdbws.com/name.basics.tsv.gz' |
| 34 | + url = "https://datasets.imdbws.com/name.basics.tsv.gz" |
34 | 35 | with urllib.request.urlopen(url) as response: |
35 | | - with tempfile.NamedTemporaryFile(mode='w+b') as archive: |
| 36 | + with tempfile.NamedTemporaryFile(mode="w+b") as archive: |
36 | 37 | shutil.copyfileobj(response, archive) |
37 | 38 | archive.seek(0) |
38 | | - with gzip.open(archive, mode='rt') as source: |
| 39 | + with gzip.open(archive, mode="rt") as source: |
39 | 40 | next(source) # Skip the header |
40 | 41 | for line in source: |
41 | | - full_name = line.split('\t')[1] |
42 | | - yield f'{full_name}\n' |
| 42 | + full_name = line.split("\t")[1] |
| 43 | + yield f"{full_name}\n" |
43 | 44 |
|
44 | 45 |
|
45 | | -if __name__ == '__main__': |
| 46 | +if __name__ == "__main__": |
46 | 47 | try: |
47 | 48 | main() |
48 | 49 | except KeyboardInterrupt: |
49 | | - print('Aborted') |
| 50 | + print("Aborted") |
0 commit comments