Last active
October 30, 2021 16:45
-
-
Save okb1100/b510ec96811c8af5ddc4d9b27b796aba to your computer and use it in GitHub Desktop.
#random [Günlük deprem verilerini alıp 2.0 şiddetinden büyük olanları yazdırır]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
#The MIT License (MIT) | |
#Copyright (c) 2016 Oğuzcan 'okb1100' Küçükbayrak | |
#Permission is hereby granted, free of charge, to any person obtaining a copy | |
#of this software and associated documentation files (the "Software"), to deal | |
#in the Software without restriction, including without limitation the rights | |
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
#copies of the Software, and to permit persons to whom the Software is | |
#furnished to do so, subject to the following conditions: | |
#The above copyright notice and this permission notice shall be included in | |
#all copies or substantial portions of the Software. | |
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
#THE SOFTWARE. | |
# | |
#DATA IS RECEIVED FROM REPUBLIC OF TURKEY PRIME MINISTRY DISASTER & EMERGENCY MANAGEMENT AUTHORITY WEBSITE | |
#VERİLER T.C. BAŞBAKANLIK AFET VE ACİL DURUM YÖNETİMİ BAŞKANLIĞI WEB SİTESİNDEN ALINMAKTADIR | |
#(http://www.deprem.gov.tr/) | |
import os | |
import codecs | |
import csv | |
#Terminal Colors | |
class bcolors: | |
HEADER = '\033[95m' | |
OKBLUE = '\033[94m' | |
OKGREEN = '\033[92m' | |
WARNING = '\033[93m' | |
FAIL = '\033[91m' | |
ENDC = '\033[0m' | |
BOLD = '\033[1m' | |
UNDERLINE = '\033[4m' | |
#Download the event list | |
def download(fileName): | |
import urllib.request | |
url = 'http://www.deprem.gov.tr/earthquake/eventfile?lastDay=1&m1=0&type=1&lang=tr' | |
urllib.request.urlretrieve(url, fileName) | |
#Convert the shitty csv file to utf-8 | |
def convertToUtf(sourceFile, targetFile): | |
with codecs.open(sourceFile, "r", "ISO-8859-15") as sourceF: | |
with codecs.open(targetFile, "w", "utf-8") as targetF: | |
while True: | |
contents = sourceF.read() | |
if not contents: | |
break | |
targetF.write(contents) | |
def readFromCsv(file): | |
with open(file, encoding='utf-8', newline='') as csvfile: | |
spamreader = list(csv.reader(csvfile)) | |
print(bcolors.BOLD + 'Bölge\t\tBüyüklük\tTarih' + bcolors.ENDC) | |
for row in spamreader[1:]: | |
if(float(row[8]) > 2.0): | |
if(row[10] != '-'): | |
#Some of the area names are just "-" on 10th row. Checking for it. | |
print(row[10] + ' ' + row[11] + '\t' + bcolors.WARNING + row[8] + bcolors.ENDC +'\t' + row[2]) | |
else: | |
print(row[13] + '\t' + bcolors.WARNING + row[8] + bcolors.ENDC + '\t' + row[2]) | |
if __name__ == '__main__': | |
#Check for a possible manually added event list | |
if not (os.path.isfile('eventToday.csv')): | |
download('eventToday.csv') | |
#Won't happen but try to read as UTF anyways | |
try: | |
readFromCsv('eventToday.csv') | |
except UnicodeDecodeError: | |
convertToUtf('eventToday.csv', 'eventUtf.csv') | |
readFromCsv('eventUtf.csv') | |
#Clean up the file mess | |
os.remove('eventToday.csv') | |
os.remove('eventUtf.csv') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment