Ejemplo n.º 1
0
def getAFile(thisURL, thisFilename):
    print(f"""
	downloading file from {thisURL}
	""")
    TStatus = WEB.getAFile(thisURL, thisFilename, isJson=True)
    if TStatus is False:
        return False
    if not os.path.isfile(thisFilename):
        print(
            f"something is wrong with my filename/file/etc.{C.NEWLINE}|{thisFilename}|"
        )
        exit(53)
    return True
def doAFileOfEventIDs(filename):
    filename = DS.ABSPATH(filename)
    if not DS.PATH.isfile(filename):
        print(f"""
the filename {filename} is invalid
""")
        exit(1)
    with open(filename, "r") as FDIDIn:
        while True:
            thisID = FDIDIn.readline()
            if not thisID:
                quit(0)
            thisID = thisID[1:-2]
            thisURL = C.GEOJSONDETAIL(thisID)
            filename = f"""temp/ID{thisID}.DEETSL.{TDS.nowStr(TDS.DT.now())}.geojson"""
            thisFilename = f"""{C.CACHEDIR(filename)}"""
            thisResult = WEB.getAFile(thisURL, thisFilename, isJson=True)
            if thisResult is True:
                doAFile(thisFilename, thisID)
Ejemplo n.º 3
0
    'mag', 'place', 'time', 'updated', 'tz', 'url', 'detail', 'felt', 'cdi',
    'mmi', 'alert', 'status', 'tsunami', 'sig', 'net', 'code', 'ids',
    'sources', 'types', 'nst', 'dmin', 'rms', 'gap', 'magType', 'type', 'title'
]
myLocation = argv[0]
if myLocation.find("DEV") > -1:
    thisFilename = "/home/will/.cache/earthquakesUSGS/" + TDS.nowStr(
    ) + ".DEV.USGS.geojson"
    myTableName = f"{C.GEOJSONEVENTSTABLENAME}Test"
else:
    thisFilename = "/home/will/.cache/earthquakesUSGS/" + TDS.nowStr(
    ) + ".USGS.geojson"
    myTableName = f"{C.GEOJSONEVENTSTABLENAME}"

if len(argv) == 1:
    WEB.getAFile(thisUrl, thisFilename)
else:
    thisFilename = argv[1]
    thisFilename = os.path.abspath(thisFilename)
    if not os.path.isfile(thisFilename):
        print(f"something is wrong with my filename\n|{thisFilename}|")
        exit(53)


# *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#
# * functions
# *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#
def addKeys(iterableToAdd, toWhichListName):
    global listOfBBoxKeys, listOfPropertyKeys, listOfGeoKeys, listOfFileKeys, listOfMetaKeys, listOf1stKeys, \
     listOfFeatureKeys
    toWhichList = []
def __main__():
	ARGV = argv[1:]
	# *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#
	# *	"-D": O_DETAILS,
	# *	"-Q": O_QUERYDETAILS,
	# *	"-d": O_ALLDAYSMRY,
	# *	"-f": O_FILE,
	# *	"-h": O_ALLHOURSMRY,
	# *	"-L": O_EVENTIDLIST,
	# *	"-m": O_ALLMONTHSMRY,
	# *	"-q": O_QUERY,
	# *	"-w": O_ALLWEEKSMRY,
	# *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#
	OPTS, ARGS = GO.getopt(ARGV, f"""D:Q:d:f:h:L:m:q:w:""")
	# print(f"""
	# opts {OPTS}
	# args {ARGS}
	# """)
	thisEventID = ""
	thisFilename = ""
	thisURL = ""
	thisFilePrefix = ""
	OPTSDICT = C1.OPTSTTDICT(OPTS)
	ARGSDICT = C1.ARGSTTDICT(ARGS)
	if OPTSDICT[C1.O_DETAILS] != "":
		thisEventID = OPTSDICT[C1.O_DETAILS]
		thisFilePrefix = "DEET"
		thisURL = C.GEOJSONDETAIL(thisEventID)
	elif OPTSDICT[C1.O_QUERYDETAILS] != "":
		thisEventID = OPTSDICT[C1.O_QUERYDETAILS]
		thisFilePrefix = "QDEET"
		thisURL = C.GEOJSONDETAILQUERY(thisEventID)
	elif OPTSDICT[C1.O_ALLDAYSMRY] != "":
		thisFilePrefix = "DAY"
		thisURL = C.GEOJSONALLSMRY("day")
	elif OPTSDICT[C1.O_FILE] != "":
		thisFilePrefix = "FILE"
		thisURL = ""
		thisFilename = OPTSDICT[C1.O_FILE]
	elif OPTSDICT[C1.O_ALLHOURSMRY] != "":
		thisFilePrefix = "HOUR"
		thisURL = C.GEOJSONALLSMRY("hour")
	elif OPTSDICT[C1.O_EVENTIDLIST] != "":
		doAFileOfEventIDs(OPTSDICT[C1.O_EVENTIDLIST])
		exit(0)
	elif OPTSDICT[C1.O_ALLMONTHSMRY] != "":
		thisFilePrefix = "MONTH"
		thisURL = C.GEOJSONALLSMRY("month")
	elif OPTSDICT[C1.O_QUERY] != "":
		thisFilePrefix = "QUERY"
		thisURL = C.GEOJSONQUERY(OPTSDICT[C1.O_QUERY])
	elif OPTSDICT[C1.O_ALLWEEKSMRY] != "":
		thisFilePrefix = "WEEK"
		thisURL = C.GEOJSONALLSMRY("week")
	else:
		print(f"""
Invalid opt set
OPTS {str(OPTS)}
ARGS {str(ARGS)}
argv {str(argv)}
""")
		exit(1)
	if thisURL != C.EMPTYSTR:
		thisPARM = f"""{dirPFX}ijsonST.{thisFilePrefix}.{TDS.nowStr(TDS.DT.now())}.json"""
		thisFilename = C.CACHEDIR(thisPARM)
		thisResult = WEB.getAFile(thisURL, thisFilename, isJson=True, dirPFX=dirPFX)
		if thisResult is False:
			print(f"""
failed to get the file {thisFilename}
from the URL {thisURL}

""")
			exit(1)
	if thisFilename != "":
		doAFile(thisFilename, myEventID=thisEventID)
		thisFilename = C.CACHEDIR(thisPARM)
		thisResult = WEB.getAFile(thisURL, thisFilename, isJson=True, dirPFX=dirPFX)
		if thisResult is False:
			print(f"""
failed to get the file {thisFilename}
from the URL {thisURL}

""")
			exit(1)
	if thisFilename != "":
		doAFile(thisFilename, myEventID=thisEventID)


tempURL = C.GEOJSONALLSMRY("day")
tempFileName = C.CACHEDIR(f"""{dirPFX}day{TDS.nowStr(TDS.DT.now())}.geojson""")
WEB.getAFile(tempURL, tempFileName, isJson=True, dirPfx=dirPFX)

tempURL = C.GEOJSONDETAIL("us6000a1p9")
tempFileName = C.CACHEDIR(f"""{dirPFX}deet{TDS.nowStr(TDS.DT.now())}.geojson""")
WEB.getAFile(tempURL, tempFileName, isJson=True, dirPfx=dirPFX)

tempURL = C.GEOJSONDETAILQUERY("us6000a1p9")
tempFileName = C.CACHEDIR(f"""{dirPFX}Qdeet{TDS.nowStr(TDS.DT.now())}.geojson""")
WEB.getAFile(tempURL, tempFileName, isJson=True, dirPfx=dirPFX)


# if __name__ == "__main__":
	# __main__()

#
myLocation = argv[0]

# thisUrl = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_[hour day week month].csv"
# geojson in case that ever becomes reality https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson
thisUrl = C.CSVFEEDALL("hour")
# thisUrl = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.csv"

# set csv file names appropriately so we can dev alongside use
if myLocation.find("DEV") > -1:
	thisFilename = "/home/will/.cache/earthquakesUSGS/" + TDS.nowStr() + ".DEV.USGS.csv"
else:
	thisFilename = "/home/will/.cache/earthquakesUSGS/" + TDS.nowStr() + ".USGS.csv"


if len(argv) == 1:
	if WEB.getAFile(thisUrl, thisFilename) is False:
		print(f"""file download was not successful""")
		exit(1)
else:
	thisFilename = argv[1]
	thisFilename = os.path.abspath(thisFilename)
	if not os.path.isfile(thisFilename):
		print(f"something is wrong with my filename\n|{thisFilename}|")
		exit(53)


with open(thisFilename) as inputFile:
	for lineNum, thisLine in enumerate(reader(inputFile)):
		if len(thisLine) != 22 or len(thisLine[0]) != 24:
			continue
		if C.DEBUGME: