Ejemplo n.º 1
0
    def GET(self):
        DBLinks = DB.doOpen(C.SQLCONFIG)
        outStr = sendMyHeader("Presets")
        SQLStr = f"""
select RID, {C.QUERIESINTITLE} from {C.QUERIESINTABLENAME};"""
        SQLRows, SQLNumRows = DB.getSqlAll(DBLinks, SQLStr)
        outStr += f"""
<table>
"""
        rowCount = 0
        for thisRow in SQLRows:
            rowState = rowCount % 1
            outStr += f"""</tr>
"""
            if int(thisRow[C.RID]) == int(C.DEFQUERYNUM):
                outStr += f"""<td class="close0r0">default</td>
"""
            else:
                outStr += f"""<td class="r1"><a href="setDefault/?QUERYNUM={thisRow[C.RID]}">
make default</a></td>
"""
            outStr += f"""
<td class="r{rowState}">
<a href="quakes?STARTRECNUM=0&QUERYNUM={thisRow[C.RID]}">{thisRow[C.QUERIESINTITLE]}</a>
</td>
</tr>
"""
            # end of for thisRow
        outStr += f"""
</table>
"""
        return outStr
def doAFile(thisFilename, myEventID=""):
	global fileEntry, usefulName, moreUsefulName, usefulBit, moreUsefulBit, dirPFX
	DBLinks = DB.doOpen(C.SQLCONFIG)
	# FDUseful = open(usefulName, "w")
	# FDUseful.write(f"""USEFULPREFIX = {C.OBSSTR}{C.NEWLINE}""")
	# FDUseful.flush()
	# FDUseful.close()
	for prefix, the_type, value in IJ.parse(open(thisFilename)):
		if prefix == "" or prefix is None:
			continue
		if prefix.find(myEventID) > -1 and myEventID != "":
			prefix = prefix.replace(myEventID, "$EVENTID$")
		thisTuple = (prefix, the_type, value)
		# itemList.append(thisTuple)
		if DB.checkUpdatePrefix(DBLinks, prefix) is False:
			emptyPFXDict = C.PREFIXEMPTYDICT()
			emptyPFXDict[C.PFXlastSeen] = TDS.nowStrSql(TDS.DT.now())
			emptyPFXDict[C.PFXfirstSeen] = TDS.nowStrSql(TDS.DT.now())
			emptyPFXDict[C.PFXprefixStr] = prefix
			emptyPFXDict[C.PFXkeyType] = the_type
			DB.insertDict(DBLinks, C.GEOJSONPREFIXTABLENAME, emptyPFXDict, C.MYFIELDTYPESDICT)
		# FDUseful = open(usefulName, "ta")
		# outStr = f"""{C.TABSTR}{C.DQTSTR}{COMBO}{C.DQTSTR},{C.NEWLINE}"""
		# FDUseful.write(outStr)
		# FDUseful.flush()
		# FDUseful.close()
		FDMoreUseful = open(moreUsefulName, "ta")
		outStr = f"""({C.DQTSTR}{prefix}{C.DQTSTR}, {C.DQTSTR}{the_type}{C.DQTSTR}, C.TYPE, """
		outStr += f"""{C.DQTSTR}headerName{C.DQTSTR}, SQLDEFAULT, SCNDEFAULT,),{C.NEWLINE}"""
		FDMoreUseful.write(f"""{str(thisTuple)}{C.NEWLINE}""")
		FDMoreUseful.flush()
		FDMoreUseful.close()
Ejemplo n.º 3
0
    def GET(self):
        global myCurrentQueries
        myCurrentQueries = C.QUERIESINGLOBALDEFAULTS
        DBLinks = DB.doOpen(C.SQLCONFIG)
        outStr = sendMyHeader("Presets")
        SQLStr = f"""
select RID, {C.QUERIESINTITLE} from {C.QUERIESINTABLENAME};"""
        SQLRows, SQLNumRows = DB.getSqlAll(DBLinks, SQLStr)
        outStr += f"""
<table>
"""
        rowCount = 0
        for thisRow in SQLRows:
            rowState = rowCount % 1
            outStr += f"""
<tr>
<td class="r{rowState}">
<a href="quakes?STARTNUM=0&QUERYNUM={thisRow[C.RID]}">{thisRow[C.QUERIESINTITLE]}</a>
</td>
</tr>
"""
            # end of for thisRow
        outStr += f"""
</table>
"""
        return outStr
Ejemplo n.º 4
0
    def GET(self):
        DBLinks = DB.doOpen(C.SQLCONFIG)
        myInput = web.input(QUERYNUM=C.DEFQUERYNUM)
        newDefault = myInput[C.QUERYNUM]
        outStr = sendMyHeader("set default query number")
        SQLStr = f"""
select RID from queriesIn where RID = {newDefault};"""
        SQLRowDict = DB.getSqlOne(DBLinks, SQLStr)
        if SQLRowDict is None:
            outStr += f"""
<span class = "fp">that was a fail<br /></span>
</body>
</html>"""
            return outStr
        outStr += f"""
		<span class="close0r0"><br />
		setting {newDefault} as the new DEFAULTQUERYNUM and returning to presets<br />
</body>
</html>
"""
        C.DEFQUERYNUM = newDefault
        C.PUTDEFQRID()
        web.seeother(f"""http://192.168.0.16:8080/presets""")
        return outStr
Ejemplo n.º 5
0
    def GET(self):
        global myCurrentQueries
        DBLinks = DB.doOpen(C.SQLCONFIG)
        myInput = web.input(STARTRECNUM=0, QUERYNUM=1)
        if myInput[C.QUERYNUM] != myCurrentQueries[C.QUERYNUM]:
            myCurrentQueries = C.QUERIESINGLOBALDEFAULTS
        myCurrentQueries[C.STARTRECNUM] = myInput[C.STARTRECNUM]
        myCurrentQueries[C.QUERYNUM] = myInput[C.QUERYNUM]
        myCurrentQueries[C.ROWNUM] = 0
        SQLStr = f"""
select * from {C.QUERIESINTABLENAME}
where {C.RID} = {myCurrentQueries[C.QUERYNUM]};"""
        SQLRowsDict = DB.getSqlOne(DBLinks, SQLStr)
        myCurrentQueries = DB.upgradeDBToGQI(SQLRowsDict,
                                             C.QUERIESINGLOBALDEFAULTS)
        outStr = sendMyHeader(
            f"{myCurrentQueries[C.QUERIESINTITLE]}  {__file__}")
        SQLStr = f"""
{myCurrentQueries[C.SQLSELECT]}
{myCurrentQueries[C.SQLWHERE]}
{myCurrentQueries[C.SQLGROUPBY]} 
{myCurrentQueries[C.SQLORDERBY]}
"""
        SQLStr += DB.saneMakeSqlLimitStr(myCurrentQueries[C.STARTRECNUM]) + ";"
        SQLRowsDict, SQLNumRows = DB.getSqlAll(DBLinks, SQLStr)
        myCurrentQueries[C.NUMROWS] = SQLNumRows
        myCurrentQueries[C.PGNUM] = int(
            int(myCurrentQueries[C.STARTRECNUM]) / C.NUMROWSPERPG) + 1
        myCurrentQueries[C.OFPGS] = int(
            int(myCurrentQueries[C.NUMROWS]) / C.NUMROWSPERPG) + 1
        # theseRows = DB.upgradeDBToGQIMany(SQLRowsDict, C.QUERIESINGLOBALDEFAULTS)
        outStr += "<table>\n"
        for thisRow in SQLRowsDict:
            thisRow = DB.DTfixThisLineToDisplay(thisRow)
            lastRow = thisRow
            outStr += DB.makeTableRow(thisRow, myCurrentQueries, 0)
            myCurrentQueries[C.ROWNUM] += 1
        outStr += DB.makeTableRow(lastRow, myCurrentQueries, 1)
        outStr += """
		</table>
		<span class="fp">bottom of the page</span>
	</body>
</html>
"""
        return outStr
Ejemplo n.º 6
0
def __main__():
    thisRowNum = 0
    addedRows = 0
    # set file names appropriately so we can dev alongside use
    global listOfPropertyKeys, listOfGeoKeys, listOfFileKeys, listOfMetaKeys, listOf1stKeys
    global listOfFeatureKeys
    with open(thisFilename, "r") as FIn:
        GJLI = GJ.load(FIn)
        addKeys(GJLI, "listOfFileKeys")
        myFileEntry = C.GEOJSONFILEENTRYEMPTYSQL()
        myFileEntry[C.fileType] = GJLI[C.type_]
        if myFileEntry[C.fileType] == "FeatureCollection":
            try:
                myMetadata = GJLI[C.metadata]
                myFileEntry[C.metaGeneratedTime] = TDS.TS2ISO(
                    myMetadata[C.generated])
                print(
                    f"""records returned {GJLI["metadata"]["count"]}/{len(GJLI[C.features])}
	generated {myFileEntry[C.metaGeneratedTime]}""")
                addKeys(myMetadata, "listOfMetaKeys")
            except KeyError:
                myMetadata = None
                myFileEntry[C.metaGeneratedTime] = ""
            try:
                myFeatures = GJLI[C.features]
            except KeyError:
                myFeatures = None
            try:
                myBoundingBox = GJLI[C.bbox]
            except KeyError:
                myBoundingBox = None
        if myMetadata is not None:
            myFileEntry[C.metaGeneratedTime] = TDS.TS2ISO(
                myMetadata[C.generated])
            for srcKey, destKey in C.METADATAEMPTY().items():
                try:
                    myFileEntry[destKey] = myMetadata[srcKey]
                except KeyError:
                    myFileEntry[destKey] = destKey
        else:
            myMetadata = C.METADATAEMPTY()
            for srcKey, destKey in myMetadata.items():
                myFileEntry[destKey] = myMetadata[srcKey]
        if myBoundingBox is not None:
            TBBox = C.BBOXEMPTY()
            for srcKey, destKey in TBBox.items():
                try:
                    myFileEntry[destKey] = myBoundingBox[srcKey]
                except KeyError:
                    myFileEntry[destKey] = destKey
        SQLResult = DB.insertDict(DBLINKS, C.GEOJSONFILEENTRYTABLENAME,
                                  myFileEntry, C.MYFIELDTYPESDICT)
        if SQLResult is not None:
            print(f"""
	something went wrong inserting a file entry row
	{str(myFileEntry)}
	GJLI
	{str(GJLI)}
	SQLResult
	{str(SQLResult)}
	""")
            exit(1)
        myFileEntry[C.RID] = DB.getInsertID(DBLINKS)
        for thisFeature in myFeatures:
            addKeys(thisFeature, listOfFeatureKeys)
            myEventEntry = C.GEOGJSONEVENTSDEFAULTSQL()
            myProperties = thisFeature[C.properties]
            addKeys(myProperties, "listOfPropertyKeys")
            myGeometry = thisFeature[C.geometry]
            addKeys(myGeometry, "listOfGeoKeys")
            myEventEntry[C.featureType] = thisFeature[C.type_]
            myEventEntry[C.fileEntryRID] = myFileEntry[C.RID]
            myEventEntry[C.eventID] = thisFeature[C.id_]
            myEventEntry[C.geoLon] = myGeometry[C.coordinates][C.BBMINLON]
            myEventEntry[C.geoLat] = myGeometry[C.coordinates][C.BBMINLAT]
            myEventEntry[C.geoDepth] = myGeometry[C.coordinates][C.BBMINDEPTH]
            myEventEntry[C.geoType] = myGeometry[C.type_]
            myEventEntry[C.featureType] = thisFeature[C.type_]
            for sourceKey, destKey in C.GEOJSONFIELDNAMES.items():
                myEventEntry[destKey] = myProperties[sourceKey]
                if C.MYFIELDTYPESDICT[sourceKey] == "varchar":
                    if not isinstance(myProperties[sourceKey], str):
                        myEventEntry[destKey] = str(myProperties[sourceKey])
                if myEventEntry[destKey] is None:
                    myEventEntry[destKey] = 0
                if C.MYFIELDTYPESDICT[destKey] == "datetime":
                    myEventEntry[destKey] = TDS.TS2ISO(myEventEntry[destKey])
            thisRowNum += 1
            if (thisRowNum % 200) == 0:
                print(".", end="")
            SQLStr = f"""select * from {C.GEOJSONEVENTSTABLENAME} where {C.eventID} = "{myEventEntry[C.eventID]}";"""
            SQLRows, numRows = DB.getSqlAll(DBLINKS, SQLStr)
            myToUpdate = False
            if numRows > 0:
                for testEvent in SQLRows:
                    returnedUpdate = TDS.toStr(testEvent[C.propUpdatedZ])
                    entryDate = TDS.toStr(myEventEntry[C.propUpdatedZ])
                    if returnedUpdate == entryDate:
                        myToUpdate = True
                        break
            if myToUpdate is True:
                # we have it already, return to looking
                continue
            SQLResult = DB.insertDict(DBLINKS, myTableName, myEventEntry,
                                      C.MYFIELDTYPESDICT)
            if SQLResult is None:
                addedRows += 1
        # end of for * in myFeatures
    # end of with geojson file
    # os.remove(thisFilename)
    print(f"""
listOfFileKeys {len(listOfFileKeys)} {str(listOfFileKeys)}
listOf1stKeys {len(listOf1stKeys)} {str(listOf1stKeys)}
listOfMetaKeys {len(listOfMetaKeys)} {str(listOfMetaKeys)}
listOfGeoKeys {len(listOfGeoKeys)} {str(listOfGeoKeys)}
listOfFeatureKeys {len(listOfFeatureKeys)} {str(listOfFeatureKeys)}
listOfPropertyKeys {len(listOfPropertyKeys)} {str(listOfPropertyKeys)}
rows added {addedRows}
""")
Ejemplo n.º 7
0
from dataStuff import timeDateStuff as TDS
from DBStuff import DBStuff as DB

myOffset = 0
gc.enable()
# thisUrl = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_[hour day week month].[csv geojson]"
if myOffset == 0:
    thisUrl = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson"
elif myOffset > 0:
    thisUrl = f"""https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&limit=10000&starttime=2019-10-01"""
    thisUrl += f"""&endtime=2019-11-01&offset={myOffset}"""
# elif myOffset == -1:
#   reserved for detail queries and then I can go out both directions for further expansion if needed

thisRowNum = 0
DBLINKS = DB.doOpen(C.SQLCONFIG)
# 4
listOfFileKeys = ['type', 'metadata', 'bbox', 'features']
# 4
listOf1stKeys = ['type', 'id', 'geometry', 'properties']
# 8
listOfMetaKeys = [
    'generated', 'url', 'title', 'status', 'api', 'count', 'limit', 'offset'
]
# 2
listOfGeoKeys = ['type', 'coordinates']
# 0
listOfFeatureKeys = []
# 26
listOfPropertyKeys = [
    'mag', 'place', 'time', 'updated', 'tz', 'url', 'detail', 'felt', 'cdi',
Ejemplo n.º 8
0
import os
from sys import argv
import gc
import geojson as GJ
# from collections.abc import Iterable as IT


from dataStuff import constants as C
from dataStuff import webStuff as WEB
from dataStuff import timeDateStuff as TDS
from DBStuff import DBStuff as DB
from dataStuff import dataStuff as DS


gc.enable()
DBLINKS = DB.doOpen(C.SQLCONFIG)
# 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
# https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_[hour day week month].geojson
# https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&eventid=nn00727575
# https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson
# myOffset = 10000
# thisUrl = """https://earthquake.usgs.gov/fdsnws/event/1/query.geojson?starttime=2020-04-21 00:00:00"""
# thisUrl += """&endtime=2020-05-21 23:59:59&minmagnitude=-1&eventtype=earthquake,acoustic noise,acoustic_noise"""
# thisUrl += """,anthropogenic_event,building collapse,chemical explosion,chemical_explosion,collapse"""
# thisUrl += """,eq,experimental explosion,explosion,ice quake,induced or triggered event,"""
# thisUrl += """industrial explosion,landslide,meteor,meteorite,mine collapse,mine_collapse"""
# thisUrl += """,mining explosion,mining_explosion,not reported,not_reported,nuclear explosion"""
# thisUrl += """,nuclear_explosion,other event,other_event,quarry,quarry blast,quarry_blast"""
# thisUrl += """,rock burst,Rock Slide,rockslide,rock_burst,snow_avalanche,sonic boom,sonicboom,sonic_boom"""
# thisUrl += f""",volcanic eruption,volcanic explosion&orderby=time&limit=10000&offset={myOffset}"""
Ejemplo n.º 9
0

from dataStuff import constants as C
from DBStuff import DBStuff as DB

DBLinks = DB.doOpen(C.SQLCONFIG)

# SQLRows = DBLinks[C.DBCURSOR].fetchall()

# DBLinks[C.DBCONNECTION].handle_unread_result()
SQLStr = f"""select EQID, count(EQID) as CEQID from USGSData where PLACE like "%Utah%";"""

SQLRows = DB.getSqlAll(DBLinks, SQLStr)
if SQLRows:
	for key, value in SQLRows.items():
		print(f"{key}: {value},", end=" ")
	print("")


DB.doClose(DBLinks)


Ejemplo n.º 10
0
    def GET(self):
        global myCurrentQueries
        DBLinks = DB.doOpen(C.SQLCONFIG)
        myInput = web.input(STARTRECNUM=0, QUERYNUM=C.DEFQUERYNUM)
        # C.QUERYLOADED (-1) if from select the parts
        # C.QUERYFROMPRESET (1) if from presets
        # C.QUERYEMPTY (0) if anything else
        if myInput[C.QUERYNUM] != myCurrentQueries[C.QUERYNUM]:
            myCurrentQueries = C.QUERIESINDEFAULTS()
            myCurrentQueries[C.QUERYNUM] = myInput[C.QUERYNUM]
            # C.QUERYLOADED if set by any of the query building parts,
            # C.QUERYFROMPRESET if loaded from a preset
            # C.QUERYEMPTY if "empty"
            myCurrentQueries[C.ISLOADED] = C.QUERYEMPTY
        myCurrentQueries[C.STARTRECNUM] = myInput[C.STARTRECNUM]
        myCurrentQueries[C.QUERYNUM] = myInput[C.QUERYNUM]
        myCurrentQueries[C.ROWNUM] = 0
        if myCurrentQueries[C.ISLOADED] != C.QUERYLOADED:
            SQLStr = f"""
select * from {C.QUERIESINTABLENAME}
where {C.RID} = {myCurrentQueries[C.QUERYNUM]};"""
            SQLRowsDict = DB.getSqlOne(DBLinks, SQLStr)
            myCurrentQueries = DB.upgradeDBToGQI(SQLRowsDict, myCurrentQueries)
            myCurrentQueries[C.ISLOADED] = 1
        C.REGIONNAMESDICT[C.REGION0NAME] = myCurrentQueries[C.REGION0NAME]
        C.REGIONNAMESDICT[C.REGION1NAME] = myCurrentQueries[C.REGION1NAME]
        C.REGIONNAMESDICT[C.REGION2NAME] = myCurrentQueries[C.REGION2NAME]
        C.REGIONNAMESDICT[C.REGION3NAME] = myCurrentQueries[C.REGION3NAME]
        C.REGIONDESCRIPTIONSDICT[C.REGION0DESCRIPTION] = myCurrentQueries[
            C.REGION0DESCRIPTION]
        C.REGIONDESCRIPTIONSDICT[C.REGION1DESCRIPTION] = myCurrentQueries[
            C.REGION1DESCRIPTION]
        C.REGIONDESCRIPTIONSDICT[C.REGION2DESCRIPTION] = myCurrentQueries[
            C.REGION2DESCRIPTION]
        C.REGIONDESCRIPTIONSDICT[C.REGION3DESCRIPTION] = myCurrentQueries[
            C.REGION3DESCRIPTION]
        outStr = sendMyHeader(f"""{myCurrentQueries[C.QUERIESINTITLE]}""",
                              f"""styleChunk.css""")
        SQLStr = f"""
{myCurrentQueries[C.SQLSELECT]}
{myCurrentQueries[C.SQLWHERE]}
{myCurrentQueries[C.SQLGROUPBY]}
{myCurrentQueries[C.SQLHAVING]}
{myCurrentQueries[C.SQLORDERBY]}
"""
        SQLStr += DB.saneMakeSqlLimitStr(myCurrentQueries[C.STARTRECNUM]) + ";"
        SQLRowsDict, SQLNumRows = DB.getSqlAll(DBLinks, SQLStr)
        myCurrentQueries[C.NUMROWS] = SQLNumRows
        myCurrentQueries[C.PGNUM] = int(
            int(myCurrentQueries[C.STARTRECNUM]) / C.NUMROWSPERPG) + 1
        myCurrentQueries[C.OFPGS] = int(
            int(myCurrentQueries[C.NUMROWS]) / C.NUMROWSPERPG) + 1
        # theseRows = DB.upgradeDBToGQIMany(SQLRowsDict, C.QUERIESINGLOBALDEFAULTS)
        outStr += f"""
<span class="labels"><br />current SQLStr<br />{SQLStr}<br /></span><br />

"""
        outStr += "<table>\n"
        if myCurrentQueries[C.NUMROWS] < 1:
            outStr += f"""
<tr>
	<td class="close0r0">no entries found</td>
	<td class="close3r0"><a href="menu">click for the menu</a></td>
</tr>
<tr>
	<td class="close3r1"><a href="presets">presets</a></td>
	<td class="close2r0"><a href="quakes/?QUERYNUM={C.DEFQUERYNUM}&STARTRECNUM=0">
		for the default preset</a></td>
</tr>
<tr>
	<td class="close2r1"><a href="stop">stop the server</a></td>
	<td class="close1r0">{TDS.nowStrSql()}</td>
</tr>
</table>
</body>
</html>

"""
            return outStr
        for thisRow in SQLRowsDict:
            thisRow = DB.DTfixThisLineToDisplay(thisRow)
            lastRow = thisRow
            outStr += DB.makeTableRow(thisRow, myCurrentQueries, 0)
            myCurrentQueries[C.ROWNUM] += 1
        outStr += DB.makeTableRow(lastRow, myCurrentQueries, 1)
        outStr += f"""
		</table>
		{DB.makeDistance()}
		<span class="fp">bottom of the page</span>
	</body>
</html>
"""
        return outStr
Ejemplo n.º 11
0
import gc
from csv import reader
import os
from sys import argv


from dataStuff import constants as C
from dataStuff import webStuff as WEB
from dataStuff import timeDateStuff as TDS
from DBStuff import DBStuff as DB
from dataStuff import dataStuff as DS


gc.enable()
DBLINKS = DB.doOpen(C.SQLCONFIG)
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: