├── requirements.txt ├── screenshot.png ├── LICENSE ├── .gitignore ├── README.md └── uscis.py /requirements.txt: -------------------------------------------------------------------------------- 1 | requests>=2.19.1 2 | beautifulsoup4>=4.7.1 3 | lxml>=4.2.1 4 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cczhong11/check_uscis_script/HEAD/screenshot.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 tianchen zhong 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # USCIS helper 2 | 3 | ![Total visitor](https://visitor-count-badge.herokuapp.com/total.svg?repo_id=cczhong11.uscis) 4 | ![Visitors in today](https://visitor-count-badge.herokuapp.com/today.svg?repo_id=cczhong11.uscis) 5 | 6 | A simple Python script help you know more about USCIS status 7 | 8 | ## Install 9 | 10 | Requirements: 11 | 12 | 1. Python3.5+ 13 | 2. Run `pip3 install -r requirements.txt` 14 | 15 | 16 | ## Run 17 | 18 | Usage: 19 | 20 | ```bash 21 | 22 | usage: uscis.py [-h] [--start START] [--range RANGE] [--loc LOC] [--seq] [-v] 23 | [-verr] 24 | 25 | optional arguments: 26 | -h, --help show this help message and exit 27 | --start START Start id 28 | --range RANGE Search range 29 | --loc LOC Process location, default is YSC 30 | --seq Start with sequential version 31 | -v print all status 32 | -verr print all error message 33 | 34 | 35 | ``` 36 | 37 | Example: 38 | 39 | ``` 40 | $ python3 uscis.py --start 1990200000 --range 100 41 | Start num is YSC1990200000 42 | End num is YSC1990200099 43 | Produced number is : 20 44 | Received number is : 73 45 | 46 | ``` 47 | 48 | Show all status 49 | 50 | ``` 51 | $ python uscis.py --start 1990200000 --range 10 --seq -v 52 | 53 | Start num is YSC1990200000 54 | End num is YSC1990200009 55 | YSC1990200000:Case Was Received 56 | YSC1990200001:Case Was Received 57 | YSC1990200002:Case Was Received 58 | YSC1990200003:Case Was Received 59 | YSC1990200004:New Card Is Being Produced 60 | YSC1990200005:Case Was Received 61 | YSC1990200006:Case Was Received 62 | YSC1990200007:Case Was Received 63 | YSC1990200008:Case Was Received 64 | YSC1990200009:Card Was Delivered To Me By The Post Office 65 | Produced number is : 2 66 | Received number is : 8 67 | 68 | ``` 69 | 70 | ## Screenshot 71 | 72 | ![](screenshot.png) 73 | 74 | 75 | If you don't know how to use it, you can add me wechat account 76 | 77 | ![](https://tczimg.s3.amazonaws.com/wechat.png) 78 | 79 | 80 | Welcome star and pull request! 81 | -------------------------------------------------------------------------------- /uscis.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import sys 3 | import re 4 | from bs4 import BeautifulSoup 5 | 6 | from multiprocessing import Pool 7 | import argparse 8 | 9 | def init_arg(parser): 10 | parser.add_argument('--start', type=int, default=1990200000, help='Start id') 11 | parser.add_argument('--range', type=int, default=100, help='Search range') 12 | parser.add_argument('--loc', type=str, default='YSC', help='Process location, default is YSC') 13 | parser.add_argument('--seq', action='store_true',help='Start with sequential version') 14 | parser.add_argument('-v', action='store_true',help='print all status') 15 | parser.add_argument('-verr', action='store_true',help='print all error message') 16 | opt = parser.parse_args() 17 | return vars(opt) 18 | 19 | class USCIS(object): 20 | 21 | def __init__(self, parser): 22 | self.opt = init_arg(parser) 23 | 24 | 25 | def getstatus(self,num): 26 | header = {"User-Agent":"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"} 27 | r= requests.post('https://egov.uscis.gov/casestatus/mycasestatus.do',headers=header,data={"changeLocale":"","appReceiptNum":num, "initCaseSearch":"CHECK STATUS"}) 28 | try: 29 | s=BeautifulSoup(r.content,"lxml") 30 | rs = s.find('div',"current-status-sec").text 31 | rs = rs.replace("Your Current Status:","") 32 | rs = re.sub(r'[\t\n\r+]',"",rs) 33 | rs_info = s.find('div', "rows text-center").text 34 | rev = 0 35 | if "Case Was Received" in rs and ("I-765" in rs_info or "I-129" in rs_info): 36 | rev = 1 37 | elif "Produced" in rs or "Delivered" in rs or "Mailed To Me" in rs or "Picked" in rs: 38 | rev = -1 39 | if rev != 0 and self.opt["v"]: 40 | print("{}:{}".format(num,rs.strip())) 41 | return rev 42 | except Exception as e: 43 | if self.opt["verr"]: 44 | print(e) 45 | return 0 46 | 47 | 48 | def multiprocess(self,nums): 49 | p = Pool(10) # if this value is too big, USCIS would block your ip 50 | rs = p.map(self.getstatus, nums) # run multi processor version 51 | p.terminate() 52 | p.join() 53 | print(f"Produced number is : {-sum(i for i in rs if i is not None and i < 0)}") 54 | print(f"Received number is : {sum(i for i in rs if i is not None and i > 0)}") 55 | 56 | def sequential(self,nums): 57 | rec = 0 58 | pro = 0 59 | for i in nums: 60 | rs = self.getstatus(i) 61 | if rs > 0: 62 | rec+=rs 63 | elif rs < 0: 64 | pro-=rs 65 | print(f"Produced number is : {pro}") 66 | print(f"Received number is : {rec}") 67 | 68 | if __name__ == "__main__": 69 | args = argparse.ArgumentParser() 70 | client = USCIS(args) 71 | 72 | search_list = [] 73 | for i in range(client.opt["range"]): 74 | search_item = f"{client.opt['loc']}{client.opt['start']+i}" 75 | search_list.append(search_item) 76 | print(f"Start num is {client.opt['loc']}{client.opt['start']}") 77 | print(f"End num is {client.opt['loc']}{client.opt['start']+client.opt['range']-1}") 78 | if client.opt["seq"]: 79 | client.sequential(search_list) 80 | else: 81 | client.multiprocess(search_list) 82 | --------------------------------------------------------------------------------