Skip to content

Commit 6a21ae4

Browse files
committed
feat: add readme to csv parser
1 parent d296c8b commit 6a21ae4

7 files changed

+1615
-1047
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/.ipynb_checkpoints
2+
**/__pycache__

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
### Leetcode Company Question List
22

3-
Curated lists of Leetcode questions group by companies, updated as of May 9, 2022.
3+
Curated lists of Leetcode questions group by companies, updated as of May, 2022.

data-gen/leetcode_scraper.ipynb

+248-15
Large diffs are not rendered by default.

data-gen/markdown2csv.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
from markdownTable import markdownTable
33
import argparse
44

5-
def markdown_to_csv(md_path, csv_path):
5+
def md_to_df(md_path):
66
df = pd.read_table(md_path, sep="|", header=0, index_col=1, skipinitialspace=True).dropna(axis=1, how='all').iloc[1:]
77
df.columns = df.columns.str.strip()
8+
return df
9+
10+
def md_to_csv(md_path, csv_path):
11+
df = md_to_df(md_path)
812
df.to_csv(csv_path, index=False)
913

1014
if __name__ == '__main__':
1115
parser = argparse.ArgumentParser(description='Convert Markdown table to CSV')
1216
parser.add_argument('--md', type=str, help='path to the source markdown file')
1317
parser.add_argument('--csv', type=str, help='path to the destination csv file')
1418
args = parser.parse_args()
15-
markdown_to_csv(args.md, args.csv)
19+
md_to_csv(args.md, args.csv)
1620

data-gen/parse_readme.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from markdown2csv import md_to_df
2+
import re
3+
import pandas as pd
4+
5+
parsed_list = []
6+
df = md_to_df('../data/leetcode_repo_readme.md')
7+
8+
for _, row in df.iterrows():
9+
name_and_link = row['Title']
10+
m = re.search(r'\[(.*)\]\((.*)\)', name_and_link)
11+
name = m[1]
12+
link = m[2]
13+
parsed_list.append((name, link, ))
14+
15+
parsed_df = pd.DataFrame(parsed_list, columns=['name', 'link'])
16+
parsed_df.to_csv('../data/leetcode_problems.csv')
17+
18+

data/leetcode_problems.csv

+1,339-1,028
Large diffs are not rendered by default.

data/leetcode_repo_readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| # | Title | Solutions | Video | Difficulty | Tag | Company
1+
| ID | Title | Solutions | Video | Difficulty | Tag | Company
22
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|-------------|-------------
33
| 2264 |[Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2264.java) || Easy ||
44
| 2260 |[Minimum Consecutive Cards to Pick Up](https://leetcode.com/problems/minimum-consecutive-cards-to-pick-up/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2260.java) || Medium ||

0 commit comments

Comments
 (0)