-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new filter_ scripts to speed up sql2csv
- Loading branch information
Showing
6 changed files
with
143 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env python3 | ||
|
||
''' | ||
Input from STDIN | ||
# CREATE TABLE `langlinks` ( | ||
# `ll_from` int(8) unsigned NOT NULL DEFAULT 0, | ||
# `ll_lang` varbinary(35) NOT NULL DEFAULT '', | ||
# `ll_title` varbinary(255) NOT NULL DEFAULT '', | ||
Output to STDOUT: ll_title, ll_from_page_id, ll_lang | ||
''' | ||
|
||
import sys | ||
|
||
for line in sys.stdin: | ||
line = line.rstrip().replace('\r', '') | ||
|
||
columns = line.split(',', 2) | ||
|
||
print(','.join([columns[2], columns[0], columns[1]])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python3 | ||
|
||
''' | ||
Input from STDIN | ||
# CREATE TABLE `page` ( | ||
# `page_id` int(8) unsigned NOT NULL AUTO_INCREMENT, | ||
# `page_namespace` int(11) NOT NULL DEFAULT 0, | ||
# `page_title` varbinary(255) NOT NULL DEFAULT '', | ||
# `page_restrictions` tinyblob DEFAULT NULL, | ||
# `page_is_redirect` tinyint(1) unsigned NOT NULL DEFAULT 0, | ||
# `page_is_new` tinyint(1) unsigned NOT NULL DEFAULT 0, | ||
# `page_random` double unsigned NOT NULL DEFAULT 0, | ||
# `page_touched` varbinary(14) NOT NULL DEFAULT '', | ||
# `page_links_updated` varbinary(14) DEFAULT NULL, | ||
# `page_latest` int(8) unsigned NOT NULL DEFAULT 0, | ||
# `page_len` int(8) unsigned NOT NULL DEFAULT 0, | ||
# `page_content_model` varbinary(32) DEFAULT NULL, | ||
# `page_lang` varbinary(35) DEFAULT NULL, | ||
Output to STDOUT: page_id, page_title | ||
''' | ||
|
||
import sys | ||
import csv | ||
|
||
reader = csv.DictReader(sys.stdin, fieldnames=[ | ||
'page_id', | ||
'page_namespace', | ||
'page_title', | ||
'page_restrictions', | ||
'page_is_redirect', | ||
'page_is_new', | ||
'page_random', | ||
'page_touched', | ||
'page_links_updated', | ||
'page_latest', | ||
'page_len', | ||
'page_content_model', | ||
'page_lang' | ||
]) | ||
writer = csv.DictWriter(sys.stdout, fieldnames=['id', 'title'], dialect='unix', quoting=csv.QUOTE_MINIMAL) | ||
|
||
for row in reader: | ||
# 0 are articles | ||
if (row['page_namespace'] != '0'): | ||
continue | ||
|
||
title = row['page_title'].replace('\r', '') | ||
if len(title) == 0: | ||
continue | ||
|
||
writer.writerow({'id': row['page_id'], 'title': title}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python3 | ||
|
||
''' | ||
Input from STDIN | ||
# CREATE TABLE `pagelinks` ( | ||
# `pl_from` int(8) unsigned NOT NULL DEFAULT 0, | ||
# `pl_namespace` int(11) NOT NULL DEFAULT 0, | ||
# `pl_title` varbinary(255) NOT NULL DEFAULT '', | ||
# `pl_from_namespace` int(11) NOT NULL DEFAULT 0, | ||
Output to STDOUT: only pl_title | ||
''' | ||
|
||
import sys | ||
import csv | ||
|
||
reader = csv.DictReader(sys.stdin, fieldnames=['pl_from', 'pl_namespace', 'pl_title', 'pl_from_namespace']) | ||
writer = csv.DictWriter(sys.stdout, fieldnames=['title'], dialect='unix', quoting=csv.QUOTE_MINIMAL) | ||
|
||
for row in reader: | ||
# 0 are articles | ||
if (row['pl_namespace'] != '0'): | ||
continue | ||
|
||
title = row['pl_title'].replace('\r', '') | ||
if len(title) == 0: | ||
continue | ||
|
||
writer.writerow({'title': title}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python3 | ||
|
||
''' | ||
Input from STDIN | ||
# CREATE TABLE `redirect` ( | ||
# `rd_from` int(8) unsigned NOT NULL DEFAULT 0, | ||
# `rd_namespace` int(11) NOT NULL DEFAULT 0, | ||
# `rd_title` varbinary(255) NOT NULL DEFAULT '', | ||
# `rd_interwiki` varbinary(32) DEFAULT NULL, | ||
# `rd_fragment` varbinary(255) DEFAULT NULL, | ||
Output to STDOUT: rd_from_page_id, rd_title | ||
''' | ||
|
||
import sys | ||
import csv | ||
|
||
reader = csv.DictReader(sys.stdin, fieldnames=[ | ||
'rd_from', | ||
'rd_namespace', | ||
'rd_title', | ||
'rd_interwiki', | ||
'rd_fragment' | ||
]) | ||
writer = csv.DictWriter(sys.stdout, fieldnames=['id', 'title'], dialect='unix', quoting=csv.QUOTE_MINIMAL) | ||
|
||
for row in reader: | ||
# 0 are articles | ||
if (row['rd_namespace'] != '0'): | ||
continue | ||
|
||
title = row['rd_title'].replace('\r', '') | ||
if len(title) == 0: | ||
continue | ||
|
||
writer.writerow({'id': row['rd_from'], 'title': title}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters