uscis case dump in a given range

I am providing a simple Python script, that one can use to download USCIS cases in agiven range. The case data may provide you an idea on time of action in your case.

Do not abuse the script and put undue pressure on USCIS system. Your IP will get blocked for abuse for long ranges. An abuse may be seen as DOS (denial of service) attack and may invoke felony proceedigs.

To use the code, edit  "START_CASE", "END_CASE" and "fname" vaiables. Read comments for details.

# Use this code very responsibly and do not abuse the system. Abusing the system may result in a felony.


import requests
#pip install htmldom
from htmldom import htmldom
import re
import os

CASE_TYPE = "I-485"
# put the start case number in full as in the example below
START_CASE = 'MSC2290530000' #MSC2290532863
# put the end case number in full as in the example below
END_CASE = 'MSC2290540000'
# file location to save the results
fname = "case-with-date.csv"

start_seq = int(START_CASE[3:]) -1
end_seq = int(END_CASE[3:]) + 1
case_prefix = START_CASE[0:3]

url = 'https://egov.uscis.gov/casestatus/mycasestatus.do'

if end_seq - start_seq > 500:
print("Your IP will get blocked after 500+ requests. Use the script in justified and responsible manner.")


if os.path.exists(fname):
os.remove(fname)


def getActionDate(text):
try:
date = re.search('\w+\s\d{1,2},\s\d{4}',text).group(0)
return date
except:
return ""


def getCaseType(text):
try:
caseType = re.search('I-\d{3}J{0,1}',text).group(0)
return caseType
except:
return "Unknown"

def getDetails(eac):
dom = htmldom.HtmlDom()
dom = dom.createDom(getStatus(eac))
dataTag = dom.find("div.uscis-seal").find('div.rows')
caseStatus = dom.find("div.uscis-seal").find('div.rows').find('h1').text()
pageText = dataTag.text()
caseType = getCaseType(pageText)
lastActionDate = getActionDate(dataTag.text())
return [caseType,caseStatus,lastActionDate]


def getStatus(receiptNumber):
payload = {'appReceiptNum': receiptNumber, 'initCaseSearch': 'CHECK STATUS'}
r = requests.post(url, data=payload,timeout=30)
return r.text



for i in range (start_seq,end_seq,1):
case_num = case_prefix+str(i)
val = getDetails(case_num)
if(val[0] == CASE_TYPE):
print (case_num +" "+ val[0] + " " + val[1] + " " + val[2])
f = open(fname, "a")
f.write(case_num +","+ val[0] + "," + val[1] + ",\"" + val[2]+"\"\n")

f.close()

Comments

Popular posts from this blog

Caused by: java.sql.SQLTimeoutException: ORA-01013: user requested cancel of current operation

HashiCorp Vault Integration with Ansible Etower using approle

utility to extract date from text with java