A package for getting information about a leetcode problem
Project description
Fetch Problem
Gets a dictionary with information about a leetcode problem, formatted in rst
- num
- title
- slug
- difficulty
- description
- list of examples
- inputs
- output
- explanation
- img
- list of constraints
- initial code snippet
- synced user code*
- function information**
- name
- list of params
- list of param types
- return type
*: requires cookies.txt
**: assumes implementing only one function for now
Usage
Installing
-
Install package from Python Package Index (PyPI) with
pip install rossmassey.fetch-leetcode-problem
-
Use
import fetch_leetcode_problem
orfrom fetch_leetcode_problem import ...
Documentation
Sphinx documentation is generated from the docstrings
https://rossmassey.github.io/fetch-leetcode-problem/
Example
In [1]: import fetch_leetcode_problem as lc
In [2]: lc.count_problems()
Out[2]: 0
In [3]: lc.update_problem_listing()
In [4]: lc.count_problems()
Out[4]: 3018
In [5]: lc.load_cookie('cookies.txt')
In [6]: lc.get_problem(1)
Out[6]:
{'num': '1',
'title': 'Two Sum',
'slug': 'two-sum',
'difficulty': 'Easy',
'description': 'Given an array of integers ``nums``\xa0and an integer ``target``, return *indices of the two numbers such that they add up to ``target``*.\n\nYou may assume that each input would have ***exactly* one solution**, and you may not use the *same* element twice.\n\nYou can return the answer in any order.\n\n',
'examples': [{'input': 'nums = [2,7,11,15], target = 9',
'output': '[0,1]',
'img': None,
'explanation': ' Because nums[0] + nums[1] == 9, we return [0, 1].\n'},
{'input': 'nums = [3,2,4], target = 6',
'output': '[1,2]',
'img': None,
'explanation': None},
{'input': 'nums = [3,3], target = 6',
'output': '[0,1]',
'img': None,
'explanation': None}],
'constraints': ['``2 <= nums.length <= 10^4``',
'``-10^9 <= nums[i] <= 10^9``',
'``-10^9 <= target <= 10^9``',
'**Only one valid answer exists.**'],
'code_snippet': 'class Solution:\n def twoSum(self, nums: List[int], target: int) -> List[int]:\n ',
'code': 'class Solution:\n def twoSum(self, nums: List[int], target: int) -> List[int]:\n \n complements = {}\n \n for i, num in enumerate(nums):\n complements[num] = i\n \n for i, num in enumerate(nums):\n if (target - num) in complements and complements[target-num] != i:\n return [i, complements[target-num]]',
'func': {'name': 'twoSum',
'params': ['self', 'nums', 'target'],
'param_types': [None, 'List[int]', 'int'],
'rtype': 'List[int]'}}
Can also run the main module like:
python -m fetch_leetcode_problem.main 1
- u: update the problem index
- c: count number of problems
<num>
: get problem info for<num>
cookies.txt
Export a Netscape HTTP Cookie File for leetcode.com
(see browser extensions).
Alternatively, create a file with the text LEETCODE_SESSION
, a tab (\t
),
and your session token. This can be found in the Network tab in developer tools,
under Request Cookies, for requests to leetcode.com
.
Save as cookies.txt
in the src/fetch_leetcode_problem/
directory, or supply
the load_cookie
function with its relative location.
copy cookies.txt to site packages
Run these commands from location of cookies.txt
for it to remain available
package_location=$(pip show rossmassey.fetch-leetcode-problem | grep Location)
package_path=$(echo package_location | cut -d ' ' -f2)
cp cookies.txt package_path
Deleting database
- Find site packages location with
pip show rossmassey.fetch-leetcode-problem
- Find
fetch_leetcode_problem
directory under site packages - Delete
problems.db
Building & Publishing to PyPI
Assume .pypirc
configured in user home directory wih PyPI credentials
rm -rf dist
python3 -m build
python3 -m twine upload --repository pypi dist/*
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for rossmassey_fetch_leetcode_problem-0.1.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3405e442342aebd263279a5eb88e2df19b328ca6da5543837b170e490ce1913a |
|
MD5 | 2a4bb52a791a49bc24d1abd7311a051b |
|
BLAKE2b-256 | 670c0e59e59166897d8ae0fa6a1b4c0473f200e45e4e60f807087052f7cb1265 |
Hashes for rossmassey_fetch_leetcode_problem-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30544ad9a1f83d9240cab6b3444605ebf1954bae3c9e0bc9019d195141125453 |
|
MD5 | 3b9fdad6ebf10c2dd1d71dab07991783 |
|
BLAKE2b-256 | a78672bfacdf05bc701095b2f57ea2ac0ca5fd447fed65d6a339b72f5bbb603a |