-
Notifications
You must be signed in to change notification settings - Fork 8
/
pyweather.py
9435 lines (8717 loc) · 551 KB
/
pyweather.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'''
_______
| \ \ / @@@;
| \ \ / `#....@
| | \ / ,;@.....;,;
| | \ / @..@........@` PyWeather
| | \ / .............@ version 0.6.3 beta
| / \ / .............@ (c) 2017-2018 - o355
|_______/ | @...........#`
| | .+@@++++@#;
| | @ ; ,
| | : ' .
| | @ # .`
| | @ # .`
'''
# The second part of the ASCII art you see was converted to ASCII from Wunderground's J icon set - the sleet icon.
# Some minor tweaking was done to straighten up the rain.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Below are special lines of code that were typed in during special times.
# Please leave them alone.
# This line of code was typed in during the solar eclipse, in Eclipse.
# (the august 2017 eclipse). Commit ID: b4c9b74731fa5ca32cd7c52eb6240f594d742750
# This line of code was typed in for the 1,000th commit (May 28, 2018)
#
# ==============
# This is beta code. It's not pretty, and I'm not following PEP 8
# guidelines. There will be bugs in this code. I will be attempting to
# follow proper guidelines later down the road.
# <---- Preload starts here ---->
# See if we're running Python 2. If so, exit out of the script.
# Import essential libraries
import configparser
import traceback
import sys
import json
import time
import codecs
import os
from random import randint
import zipfile
from platform import python_version
# Import requests for URL downloading
try:
import requests
except ImportError:
print("When attempting to import the library requests, we ran into an import error.",
"Please make sure that requests is installed.",
"Press enter to exit.", sep="\n")
input()
sys.exit()
try:
import click
except ImportError:
print("When attempting to import the library click, we ran into an import error.",
"Please make sure that click is installed. Press enter to exit.", sep="\n")
input()
sys.exit()
try:
from colorama import init, Fore, Style
import colorama
except ImportError:
print("When attempting to import the library colorama, we ran into an import error.",
"Please make sure that colorama is installed.",
"Press enter to exit.", sep="\n")
input()
sys.exit()
try:
import geopy
from geopy import GoogleV3
except:
print("When attempting to import the library geopy, we ran into an import error.",
"Please make sure that geopy is installed.",
"Press enter to exit.", sep="\n")
input()
sys.exit()
try:
from halo import Halo
except ImportError:
print("When attempting to import the library halo, we ran into an import error.",
"Please make sure that halo is installed.",
"Press enter to exit.", sep="\n")
# Try loading the versioninfo.txt file. If it isn't around, create the file with
# the present version info.
try:
versioninfo = open('updater//versioninfo.txt').close()
except:
print("An error occurred while attempting to read the version information file.",
"This error is likely being caused by launching PyWeather outside of the pyweather folder.",
"Please try launching PyWeather when inside the PyWeather folder, and make sure that updater/versioninfo.txt",
"is accessible. You can recreate the version info file by running setup.py or configsetup.py.", sep="\n")
sys.exit()
# Define configparser under config, and read the config. - Section 3
config = configparser.ConfigParser()
config.read('storage//config.ini')
# See if the config is "provisioned". If it isn't, a KeyError will occur,
# because it's not created. Creative. - Section 4
try:
configprovisioned = config.getboolean('USER', 'configprovisioned')
except:
print("We ran into an error. Full traceback below.")
traceback.print_exc()
# Not doing a separate script launch. Doing sys.exit in that script would just continue
# PyWeather. We ask the user to run the script themselves.
print("This isn't good. Your config file isn't provisioned.",
"If you're new to PyWeather, you should run the setup script.",
"Otherwise, try launching configsetup.py, which is available in the",
"storage folder. Press enter to exit.", sep="\n")
input()
sys.exit()
# Try to parse configuration options. - Section 5
# Set a variable counting the config issues we run into. Display a message at the bottom
# of this code if we encounter 1 or more config errors.
configerrorcount = 0
try:
sundata_summary = config.getboolean('SUMMARY', 'sundata_summary')
except:
print("When attempting to load your configuration file, an error occurred.",
"SUMMARY/sundata_summary failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
sundata_summary = False
try:
almanac_summary = config.getboolean('SUMMARY', 'almanac_summary')
except:
print("When attempting to load your configuration file, an error occurred.",
"SUMMARY/almanac_summary failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
almanac_summary = False
try:
checkforUpdates = config.getboolean('UPDATER', 'autocheckforupdates')
except:
print("When attempting to load your configuration file, an error occurred.",
"UPDATER/autocheckforupdates failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
checkforUpdates = False
try:
verbosity = config.getboolean('VERBOSITY', 'verbosity')
except:
print("When attempting to load your configuration file, an error occurred.",
"VERBOSITY/verbosity failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
verbosity = False
try:
jsonVerbosity = config.getboolean('VERBOSITY', 'json_verbosity')
except:
print("When attempting to load your configuration file, an error occurred.",
"VERBOSITY/json_verbosity failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
jsonVerbosity = False
try:
tracebacksEnabled = config.getboolean('TRACEBACK', 'tracebacks')
except:
print("When attempting to load your configuration file, an error occurred.",
"TRACEBACK/tracebacks failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
tracebacksEnabled = False
try:
prefetch10Day_atStart = config.getboolean('PREFETCH', '10dayfetch_atboot')
except:
print("When attempting to load your configuration file, an error occurred.",
"PREFETCH/10dayfetch_atboot failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
prefetch10Day_atStart = False
try:
user_enterToContinue = config.getboolean('UI', 'show_enterToContinue')
except:
print("When attempting to load your configuration file, an error occurred.",
"UI/show_enterToContinue failed to load. Defaulting to True.", sep="\n")
configerrorcount += 1
user_enterToContinue = True
try:
user_showCompletedIterations = config.getboolean('UI', 'show_completedIterations')
except:
print("When attempting to load your configuration file, an error occurred.",
"UI/show_completedIterations failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
user_showCompletedIterations = False
try:
user_showUpdaterReleaseTag = config.getboolean('UPDATER', 'show_updaterReleaseTag')
except:
print("When attempting to load your configuration file, an error occurred.",
"UPDATER/show_updaterReleaseTag failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
user_showUpdaterReleaseTag = False
try:
user_backupKeyDirectory = config.get('KEYBACKUP', 'savedirectory')
except:
print("When attempting to load your configuration file, an error occurred.",
"KEYBACKUP/savedirectory failed to load. Defaulting to 'backup//'.", sep="\n")
configerrorcount += 1
user_backupKeyDirectory = 'backup//'
try:
validateAPIKey = config.getboolean('PYWEATHER BOOT', 'validateAPIKey')
except:
print("When attempting to load your configuration file, an error occurred.",
"PYWEATHER BOOT/validateAPIKey failed to load. Defaulting to True.", sep="\n")
configerrorcount += 1
validateAPIKey = True
try:
showAlertsOnSummary = config.getboolean('SUMMARY', 'showAlertsOnSummary')
except:
print("When attempting to load your configuration file, an error occurred.",
"SUMMARY/showAlertsOnSummary failed to load. Defaulting to True.", sep="\n")
configerrorcount += 1
showAlertsOnSummary = True
try:
showyesterdayonsummary = config.getboolean('SUMMARY', 'showyesterdayonsummary')
except:
print("When attempting to load your configuration file, an error occurred.",
"SUMMARY/showyesterdayonsummary failed to load. Defaulting to False", sep="\n")
showyesterdayonsummary = False
try:
showUpdaterReleaseNotes = config.getboolean('UPDATER', 'showReleaseNotes')
except:
print("When attempting to load your configuration file, an error occurred.",
"UPDATER/showReleaseNotes failed to load. Defaulting to True.", sep="\n")
configerrorcount += 1
showUpdaterReleaseNotes = True
try:
showUpdaterReleaseNotes_uptodate = config.getboolean('UPDATER', 'showReleaseNotes_uptodate')
except:
print("When attempting to load your configuration file, an error occurred.",
"UPDATER/showReleaseNotes_uptodate failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
showUpdaterReleaseNotes_uptodate = False
try:
showNewVersionReleaseDate = config.getboolean('UPDATER', 'showNewVersionReleaseDate')
except:
print("When attempting to load your configuration file, an error occurred.",
"UPDATER/showNewVersionReleaseDate failed to load. Defaulting to True.", sep="\n")
configerrorcount += 1
showNewVersionReleaseDate = True
try:
cache_enabled = config.getboolean('CACHE', 'enabled')
except:
print("When attempting to load your configuration file, an error occurred.",
"CACHE/enabled failed to load. Defaulting to True.", sep="\n")
configerrorcount += 1
cache_enabled = True
try:
cache_alertstime = config.getfloat('CACHE', 'alerts_cachedtime')
cache_alertstime = cache_alertstime * 60
except:
print("When attempting to load your configuration file, an error occurred.",
"CACHE/alerts_cachedtime failed to load. Defaulting to 300.", sep="\n")
configerrorcount += 1
cache_alertstime = 300
try:
cache_currenttime = config.getfloat('CACHE', 'current_cachedtime')
cache_currenttime = cache_currenttime * 60
except:
print("When attempting to load your configuration file, an error occurred.",
"CACHE/current_cachedtime failed to load. Defaulting to 600.", sep="\n")
configerrorcount += 1
cache_currenttime = 600
try:
cache_forecasttime = config.getfloat('CACHE', 'forecast_cachedtime')
cache_forecasttime = cache_forecasttime * 60
except:
print("When attempting to load your configuration file, an error occurred.",
"CACHE/forecast_cachedtime failed to load. Defaulting to 3600.", sep="\n")
configerrorcount += 1
cache_forecasttime = 3600
try:
cache_almanactime = config.getfloat('CACHE', 'almanac_cachedtime')
cache_almanactime = cache_almanactime * 60
except:
print("When attempting to load your configuration file, an error occurred.",
"CACHE/almanac_cachedtime failed to load. Defaulting to 14400.", sep="\n")
configerrorcount += 1
cache_almanactime = 14400
try:
cache_threedayhourly = config.getfloat('CACHE', 'threedayhourly_cachedtime')
cache_threedayhourly = cache_threedayhourly * 60
except:
print("When attempting to load your configuration file, an error occurred.",
"CACHE/threedayhourly_cachedtime failed to load. Defaulting to 3600.", sep="\n")
configerrorcount += 1
cache_threedayhourly = 3600
try:
cache_tendayhourly = config.getfloat('CACHE', 'tendayhourly_cachedtime')
cache_tendayhourly = cache_tendayhourly * 60
except:
print("When attempting to load your configuration file, an error occurred.",
"CACHE/tendayhourly_cachedtime failed to load. Defaulting to 3600.", sep="\n")
configerrorcount += 1
cache_tendayhourly = 3600
try:
cache_sundatatime = config.getfloat('CACHE', 'sundata_cachedtime')
cache_sundatatime = cache_sundatatime * 60
except:
print("When attempting to load your configuration file, an error occurred.",
"CACHE/sundata_cachedtime failed to load. Defaulting to 28800.", sep="\n")
configerrorcount += 1
cache_sundatatime = 28800
try:
cache_tidetime = config.getfloat('CACHE', 'tide_cachedtime')
cache_tidetime = cache_tidetime * 60
except:
print("When attempting to load your configuration file, an error occurred.",
"CACHE/tide_cachedtime failed to load. Defaulting to 28800.", sep="\n")
configerrorcount += 1
cache_tidetime = 28800
try:
cache_hurricanetime = config.getfloat('CACHE', 'hurricane_cachedtime')
cache_hurricanetime = cache_hurricanetime * 60
except:
print("When attempting to load your configuration file, an error occurred.",
"CACHE/hurricane_cachedtime failed to load. Defaulting to 10800.", sep="\n")
configerrorcount += 1
cache_hurricanetime = 10800
try:
cache_yesterdaytime = config.getfloat('CACHE', 'yesterday_cachedtime')
cache_yesterdaytime = cache_yesterdaytime * 60
except:
print("When attempting to load your configuration file, an error occurred.",
"CACHE/yesterday_cachedtime failed to load. Defaulting to 10800.", sep="\n")
configerrorcount += 1
cache_yesterdaytime = 10800
try:
user_radarImageSize = config.get('RADAR GUI', 'radar_imagesize')
except:
print("When attempting to load your configuration file, an error occurred.",
"RADAR GUI/radar_imagesize failed to load. Defaulting to 'normal'.", sep="\n")
configerrorcount += 1
user_radarImageSize = "normal"
try:
radar_bypassconfirmation = config.getboolean('RADAR GUI', 'bypassconfirmation')
except:
print("When attempting to load your configuration file, an error occurred.",
"RADAR GUI/bypassconfirmation failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
radar_bypassconfirmation = False
try:
showTideOnSummary = config.getboolean('SUMMARY', 'showtideonsummary')
except:
print("When attempting to load your configuration file, an error occurred.",
"SUMMARY/showtideonsummary failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
showTideOnSummary = False
try:
geopyScheme = config.get('GEOCODER', 'scheme')
except:
print("When attempting to load your configuration file, an error occurred.",
"GEOCODER/scheme failed to load. Defaulting to 'https'.", sep="\n")
configerrorcount += 1
geopyScheme = 'https'
try:
prefetchHurricane_atboot = config.getboolean('PREFETCH', 'hurricanedata_atboot')
except:
print("When attempting to load your configuration file, an error occurred.",
"PREFETCH/hurricanedata_atboot failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
prefetchHurricane_atboot = False
try:
geoip_enabled = config.getboolean('FIRSTINPUT', 'geoipservice_enabled')
except:
print("When attempting to load your configuration file, an error occurred.",
"FIRSTINPUT/geoipservice_enabled failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
geoip_enabled = False
try:
pws_enabled = config.getboolean('FIRSTINPUT', 'allow_pwsqueries')
except:
print("When attempting to load your configuration file, an error occurred.",
"FIRSTINPUT/allow_pwsqueries failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
pws_enabled = False
try:
hurricanenearestcity_enabled = config.getboolean('HURRICANE', 'enablenearestcity')
except:
print("When attempting to load your configuration file, an error occurred.",
"HURRICANE/enablenearestcity failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
hurricanenearestcity_enabled = False
try:
hurricanenearestcity_fenabled = config.getboolean('HURRICANE', 'enablenearestcity_forecast')
except:
print("When attempting to load your configuration file, an error occurred.",
"HURRICANE/enablenearestcity_forecast failed to load. Defaulting to False", sep="\n")
configerrorcount += 1
hurricanenearestcity_fenabled = False
try:
geonames_apiusername = config.get('HURRICANE', 'api_username')
except:
print("When attempting to load your configuration file, an error occurred.",
"HURRICANE/api_username failed to load. Defaulting to 'pyweather_proj'", sep="\n")
configerrorcount += 1
geonames_apiusername = "pyweather_proj"
try:
hurricane_nearestsize = config.get('HURRICANE', 'nearestcitysize')
except:
print("When attempting to load your configuration file, an error occurred.",
"HURRICANE/nearestcitysize failed to load. Defaulting to 'medium'.", sep="\n")
configerrorcount += 1
hurricane_nearestsize = 'medium'
try:
favoritelocation_enabled = config.getboolean('FAVORITE LOCATIONS', 'enabled')
except:
print("When attempting to load your configuration file, an error occurred.",
"FAVORITE LOCATIONS/enabled failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
favoritelocation_enabled = False
try:
favoritelocation_1 = config.get('FAVORITE LOCATIONS', 'favloc1')
except:
print("When attempting to load your configuration file, an error occurred.",
"FAVORITE LOCATIONS/favloc1 failed to load. Defaulting to 'None'.", sep="\n")
configerrorcount += 1
favoritelocation_1 = "None"
try:
favoritelocation_2 = config.get('FAVORITE LOCATIONS', 'favloc2')
except:
print("When attempting to load your configuration file, an error occurred.",
"FAVORITE LOCATIONS/favloc2 failed to load. Defaulting to 'None'.", sep="\n")
configerrorcount += 1
favoritelocation_2 = "None"
try:
favoritelocation_3 = config.get('FAVORITE LOCATIONS', 'favloc3')
except:
print("When attempting to load your configuration file, an error occurred.",
"FAVORITE LOCATIONS/favloc3 failed to load. Defaulting to 'None'.", sep="\n")
configerrorcount += 1
favoritelocation_3 = "None"
try:
favoritelocation_4 = config.get('FAVORITE LOCATIONS', 'favloc4')
except:
print("When attempting to load your configuration file, an error occurred.",
"FAVORITE LOCATIONS/favloc4 failed to load. Defaulting to 'None'.", sep="\n")
configerrorcount += 1
favoritelocation_4 = "None"
try:
favoritelocation_5 = config.get('FAVORITE LOCATIONS', 'favloc5')
except:
print("When attempting to load your configuration file, an error occurred.",
"FAVORITE LOCATIONS/favloc5 failed to load. Defaulting to 'None'.", sep="\n")
configerrorcount += 1
favoritelocation_5 = "None"
try:
favoritelocation_1data = config.get('FAVORITE LOCATIONS', 'favloc1_data')
except:
print("When attempting to load your configuration file, an error occurred.",
"FAVORITE LOCATIONS/favloc1_data failed to load. Defaulting to 'None'.", sep="\n")
configerrorcount += 1
favoritelocation_1data = "None"
try:
favoritelocation_2data = config.get('FAVORITE LOCATIONS', 'favloc2_data')
except:
print("When attempting to load your configuration file, an error occurred.",
"FAVORITE LOCATIONS/favloc2_data failed to load. Defaulting to 'None'.", sep="\n")
configerrorcount += 1
favoritelocation_2data = "None"
try:
favoritelocation_3data = config.get('FAVORITE LOCATIONS', 'favloc3_data')
except:
print("When attempting to load your configuration file, an error occurred.",
"FAVORITE LOCATIONS/favloc3_data failed to load. Defaulting to 'None'.", sep="\n")
configerrorcount += 1
favoritelocation_3data = "None"
try:
favoritelocation_4data = config.get('FAVORITE LOCATIONS', 'favloc4_data')
except:
print("When attempting to load your configuration file, an error occurred.",
"FAVORITE LOCATIONS/favloc4_data failed to load. Defaulting to 'None'.", sep="\n")
configerrorcount += 1
favoritelocation_4data = "None"
try:
favoritelocation_5data = config.get('FAVORITE LOCATIONS', 'favloc5_data')
except:
print("When attempting to load your configuration file, an error occurred.",
"FAVORITE LOCATIONS/favloc5_data failed to load. Defaulting to 'None'.", sep="\n")
favoritelocation_5data = "None"
try:
geocoder_customkeyEnabled = config.getboolean('GEOCODER API', 'customkey_enabled')
except:
print("When attempting to load your configuration file, an error occurred.",
"GEOCODER API/customkey_enabled failed to load. Defaulting to False.", sep="\n")
configerrorcount += 1
geocoder_customkeyEnabled = False
try:
geocoder_customkey = config.get('GEOCODER API', 'customkey')
except:
print("When attempting to load your configuration file, an error occurred.",
"GEOCODER API/customkey failed to load. Defaulting to 'None'.", sep="\n")
configerrorcount += 1
geocoder_customkey = "None"
try:
extratools_enabled = config.getboolean('UI', 'extratools_enabled')
except:
print("When attempting to load your configuration file, an error occurred.",
"UI/extratools_enabled failed to load. Defaulting to 'False'.", sep="\n")
configerrorcount += 1
extratools_enabled = False
try:
prefetch_yesterdaydata = config.getboolean('PREFETCH', 'yesterdaydata_atboot')
except:
print("When attempting to load your configuration file, an error occurred.",
"PREFETCH/yesterdaydata_atboot failed to load. Defaulting to 'False'.", sep="\n")
configerrorcount += 1
prefetch_yesterdaydata = False
try:
yesterdaydata_onsummary = config.getboolean('SUMMARY', 'showyesterdayonsummary')
except:
print("When attempting to load your configuration file, an error occurred.",
"SUMMARY/showyesterdayonsummary failed to load. Defaulting to 'False'.", sep="\n")
configerrorcount += 1
yesterdaydata_onsummary = False
try:
airports_enabled = config.getboolean('FIRSTINPUT', 'allow_airportqueries')
except:
print("When attempting to load your configuration file, an error occurred.",
"FIRSTINPUT/allow_airportqueries failed to load. Defaulting to 'True'.", sep="\n")
configerrorcount += 1
airports_enabled = True
# New UI iteration variables reading thing yay
try:
hourlyinfo_iterations = config.getint('UI', 'hourlyinfo_iterations')
except:
print("When attempting to load your configuration file, an error occurred.",
"UI/hourlyinfo_iterations failed to load. Defaulting to '2'.", sep="\n")
configerrorcount += 1
hourlyinfo_iterations = 2
try:
forecastinfo_iterations = config.getint('UI', 'forecastinfo_iterations')
except:
print("When attempting to load your configuration file, an error occurred.",
"UI/forecastinfo_iterations failed to load. Defaulting to '3'.", sep="\n")
configerrorcount += 1
forecastinfo_iterations = 3
try:
hurricaneinfo_iterations = config.getint('UI', 'hurricaneinfo_iterations')
except:
print("When attempting to load your configuration file, an error occurred.",
"UI/hurricaneinfo_iterations failed to load. Defaulting to '2'.", sep="\n")
configerrorcount += 1
hurricaneinfo_iterations = 2
try:
tideinfo_iterations = config.getint('UI', 'tideinfo_iterations')
except:
print("When attempting to load your configuration file, an error occurred.",
"UI/tideinfo_iterations failed to load. Defaulting to '6'.", sep="\n")
configerrorcount += 1
tideinfo_iterations = 6
try:
historicalhourly_iterations = config.getint('UI', 'historicalhourly_iterations')
except:
print("When attempting to load your configuration file, an error occurred.",
"UI/historicalhourly_iterations failed to load. Defaulting to '2'.", sep="\n")
configerrorcount += 1
historicalhourly_iterations = 2
try:
yesterdayhourly_iterations = config.getint('UI', 'yesterdayhourly_iterations')
except:
print("When attempting to load your configuration file, an error occurred.",
"UI/yesterdayhourly_iterations failed to load. Defaulting to '3'.", sep="\n")
configerrorcount += 1
yesterdayhourly_iterations = 3
try:
alertsus_iterations = config.getint('UI', 'alertsus_iterations')
except:
print("When attempting to load your configuration file, an error occurred.",
"UI/alertsus_iterations failed to load. Defailting to '1'.", sep="\n")
configerrorcount += 1
alertsus_iterations = 1
try:
alertseu_iterations = config.getint('UI', 'alertseu_iterations')
except:
print("When attempting to load your configuration file, an error occurred.",
"UI/alertseu_iterations failed to load. Defaulting to '2'.", sep="\n")
configerrorcount += 1
alertseu_iterations = 2
if configerrorcount >= 1:
print("", "When trying to load your configuration file, error(s) occurred.",
"Try making sure that there are no typos in your config file, and try setting values",
"in your config file to the default values as listed above. If all else fails, try using",
"configsetup.py to set all config options to their defaults. If issues still occur,",
"report the bug on GitHub.", sep="\n")
# Import logging, and set up the logger. - Section 6
import logging
logger = logging.getLogger(name='pyweather_0.6.3beta')
logformat = '%(asctime)s | %(levelname)s | %(message)s'
logging.basicConfig(format=logformat)
# Set the logger levels by design. Critical works as a non-verbosity
# option, as I made sure not to have any critical messages. - Section 7
if verbosity:
logger.setLevel(logging.DEBUG)
elif tracebacksEnabled:
logger.setLevel(logging.ERROR)
else:
logger.setLevel(logging.CRITICAL)
# Initialize the halo spinner - Section 8
spinner = Halo(text='Loading PyWeather...', spinner='line')
spinner.start()
# List config options for those who have verbosity enabled. - Section 9
logger.info("PyWeather 0.6.3 beta now starting.")
logger.info("Configuration options are as follows: ")
logger.debug("sundata_summary: %s ; almanac_summary: %s" % (sundata_summary, almanac_summary))
logger.debug("checkforUpdates: %s ; verbosity: %s" % (checkforUpdates, verbosity))
logger.debug("jsonVerbosity: %s ; tracebacksEnabled: %s" % (jsonVerbosity, tracebacksEnabled))
logger.debug("prefetch10Day_atStart: %s ; user_enterToContinue: %s" % (prefetch10Day_atStart, user_enterToContinue))
logger.debug("user_showCompletedIterations: %s ; user_showUpdaterReleaseTag: %s" % (user_showCompletedIterations, user_showUpdaterReleaseTag))
logger.debug("user_backupKeyDirectory: %s ; validateAPIKey: %s" % (user_backupKeyDirectory, validateAPIKey))
logger.debug("showAlertsOnSummary: %s ; showyesterdayonsummary: %s" % (showAlertsOnSummary, showyesterdayonsummary))
logger.debug("showUpdaterReleaseNotes: %s ; showUpdaterReleaseNotes_uptodate: %s" % (showUpdaterReleaseNotes, showUpdaterReleaseNotes_uptodate))
logger.debug("showNewVersionReleaseDate: %s ; cache_enabled: %s" % (showNewVersionReleaseDate, cache_enabled))
logger.debug("cache_alertstime: %s ; cache_currenttime: %s" % (cache_alertstime, cache_currenttime))
logger.debug("cache_forecasttime: %s ; cache_almanactime: %s" % (cache_forecasttime, cache_almanactime))
logger.debug("cache_threedayhourly: %s ; cache_tendayhourly: %s" % (cache_threedayhourly, cache_tendayhourly))
logger.debug("cache_sundatatime: %s" % cache_sundatatime)
# Coded during 70% totality of the 2017 eclipse, max for my location then
logger.debug("cache_tidetime: %s" % cache_tidetime)
# Please don't touch this line kthxbye
logger.info("Setting gif x and y resolution for radar...")
# Set the size of the radar window. - Section 10
if user_radarImageSize == "extrasmall":
radar_gifx = "320"
radar_gify = "240"
elif user_radarImageSize == "small":
radar_gifx = "480"
radar_gify = "360"
elif user_radarImageSize == "normal":
radar_gifx = "640"
radar_gify = "480"
elif user_radarImageSize == "large":
radar_gifx = "960"
radar_gify = "720"
elif user_radarImageSize == "extralarge":
radar_gifx = "1280"
radar_gify = "960"
else:
radar_gifx = "640"
radar_gify = "480"
user_radarImageSize = "normal"
# Set the user radar image size to frontend_currentRadarSize for radar resolution switching
frontend_currentRadarSize = user_radarImageSize
logger.info("Defining custom functions...")
# Define custom functions - Section 11
def printException():
# We use tracebacksEnabled here, as it just worked.
if tracebacksEnabled == True:
print("Here's the full traceback (for bug reporting):")
traceback.print_exc()
def printException_loggerwarn():
# Same idea. If the print_exc was in just logger.warn, it'd print even
# if verbosity was disabled.
if verbosity == True:
logger.warning("Snap! We hit a non-critical error. Here's the traceback.")
traceback.print_exc()
def radar_clearImages():
logger.debug("clearing temporary images...")
logger.debug("removing r10.gif...")
try:
os.remove("temp//r10.gif")
except:
printException_loggerwarn()
logger.debug("removing r20.gif...")
try:
os.remove("temp//r20.gif")
except:
printException_loggerwarn()
logger.debug("removing r40.gif...")
try:
os.remove("temp//r40.gif")
except:
printException_loggerwarn()
logger.debug("removing r60.gif...")
try:
os.remove("temp//r60.gif")
except:
printException_loggerwarn()
logger.debug("removing r80.gif...")
try:
os.remove("temp//r80.gif")
except:
printException_loggerwarn()
logger.debug("removing r100.gif...")
try:
os.remove("temp//r100.gif")
except:
printException_loggerwarn()
logger.info("Declaring geocoder type...")
# Declare geocoder type - Section 12
if geopyScheme == "https" and geocoder_customkeyEnabled is False:
geolocator = GoogleV3(scheme='https')
logger.debug("geocoder scheme is now https, no custom key")
# If the user has a custom key enabled, do a geocode to validate the custom API key.
# The option to turn this off will be added in 0.6.4 beta.
elif geopyScheme == "https" and geocoder_customkeyEnabled is True:
geolocator = GoogleV3(api_key=geocoder_customkey, scheme='https')
spinner.stop()
spinner.start(text="Validating geocoder API key...")
logger.debug("geocoder scheme is now https, custom key. Validating...")
# Do a warm-up geocode
try:
location = geolocator.geocode("123 5th Avenue, New York, NY")
except:
logger.debug("warmup geocode failed.")
# Do the actual geocode
try:
location = geolocator.geocode("123 5th Avenue, New York, NY")
except geopy.exc.GeocoderQueryError:
spinner.fail(text="Geocoder API key is invalid!")
print("")
logger.debug("API key is invalid, falling back to no API key...")
print("Your geocoder API key failed to validate, since it is wrong.",
"Falling back to no API key...", sep="\n")
printException()
geolocator = GoogleV3(scheme='https')
# Sleep the loading process for 100ms, this should give enough time to let the traceback get
# printed, and let the loader continue
time.sleep(0.1)
spinner.start(text="Loading PyWeather...")
except:
spinner.fail(text="Failed to validate geocoder API key!")
print("")
print("When trying to validate your geocoder API key, something went wrong.",
"Falling back to no API key...", sep="\n")
printException()
logger.debug("Failed to validate API key.")
geolocator = GoogleV3(scheme='https')
time.sleep(0.1)
spinner.start(text="Loading PyWeather...")
elif geopyScheme == "http" and geocoder_customkeyEnabled is False:
geolocator = GoogleV3(scheme='http')
logger.debug("geocoder scheme is now http.")
elif geopyScheme == "http" and geocoder_customkeyEnabled is True:
spinner.fail(text="A custom geocoder key on a HTTP scheme isn't allowed!")
print("Sorry! Having a custom geocoder key on a HTTP scheme is not supported by",
"Google. If you want to get rid of these error messages, please set GEOCODER API/",
"customkeyenabled to False.", sep="\n")
print("")
geolocator = GoogleV3(scheme='http')
else:
print("Geocoder scheme variable couldn't be understood.",
"Defaulting to the https scheme.", sep="\n")
geolocator = GoogleV3(scheme='https')
logger.debug("geocoder scheme is now https.")
logger.info("Declaring hurricane nearest city population minimum...")
# Set hurricane nearest city size depending on the config option - Section 13
if hurricane_nearestsize == "small":
hurricane_citiesamp = "&cities=cities1000"
elif hurricane_nearestsize == "medium":
hurricane_citiesamp = "&cities=cities5000"
elif hurricane_nearestsize == "large":
hurricane_citiesamp = "&cities=cities10000"
# Declare historical cache dictionary - Section 14
historical_cache = {}
logger.debug("historical_cache: %s" % historical_cache)
logger.debug("Begin API keyload...")
# Load the API key - Section 15
try:
# Initially load the key - Section 15a
apikey_load = open('storage//apikey.txt')
logger.debug("apikey_load = %s" % apikey_load)
apikey = apikey_load.read()
except FileNotFoundError:
spinner.fail(text="Failed to access your primary API key!")
print("")
print("Your primary API key couldn't be loaded, as PyWeather ran into",
"an error when attempting to access it. Make sure that your primary key",
"file can be accessed (usually found at storage/apikey.txt. Make sure it has",
"proper permissions, and that it exists). In the mean time, we're attempting",
"to load your backup API key.", sep="\n")
# If the key isn't found, try to find the second key. - Section 15b
spinner.start(text="Loading PyWeather...")
try:
apikey2_load = open(user_backupKeyDirectory + "backkey.txt")
logger.debug("apikey2_load: %s" % apikey2_load)
apikey = apikey2_load.read()
logger.debug("apikey: %s" % apikey)
spinner.succeed(text="Successfully loaded your backup key!")
spinner.start(text="Loading PyWeather...")
except FileNotFoundError:
spinner.fail(text="Failed to access a primary & backup key!")
print("")
print("When attempting to access your backup API key, PyWeather ran into",
"an error. Make sure that your backup key file is accessible (wrong",
"permissions and the file not existing are common issues).", sep="\n")
logger.warning("Couldn't load the primary or backup key text file!" +
" Does it exist?")
print("Press enter to continue.")
input()
sys.exit()
# API keys shoudn't have spaces. Fixes #78.
# Just in case, let's also remove tabs and newlines.
apikey = apikey.replace(" ","").replace("\n","").replace("\t","")
# Validate the user's API key for the full API key validation - Section 16
if validateAPIKey == True:
# If the primary API key is valid, and got through the check,
# this is here for those who validate their API key, and making sure
# we can find their backup key.
logger.info("Making sure the backup key can be found.")
try:
apikey2_load = open(user_backupKeyDirectory + "backkey.txt")
logger.debug("apikey2_load: %s" % apikey2_load)
apikey2 = apikey2_load.read()
backupKeyLoaded = True
logger.debug("apikey2: %s ; backupKeyLoaded: %s" %
(apikey2, backupKeyLoaded))
except:
logger.warn("Could not load the backup key for future validation.")
# If we can't find it, a variable is set for future use.
backupKeyLoaded = False
logger.debug("backupKeyLoaded: %s" % backupKeyLoaded)
else:
backupKeyLoaded = False
logger.debug("apikey = %s" % apikey)
# Version info gets defined here.
buildnumber = 63
buildversion = '0.6.3 beta'
# Refresh flag variables go here.
refresh_currentflagged = False
refresh_alertsflagged = False
refresh_hourly36flagged = False
refresh_hourly10flagged = False
refresh_forecastflagged = False
refresh_almanacflagged = False
refresh_sundataflagged = False
refresh_tidedataflagged = False
refresh_hurricanedataflagged = False
refresh_yesterdaydataflagged = False
logger.debug("refresh_currentflagged: %s ; refresh_alertsflagged: %s" %
(refresh_currentflagged, refresh_alertsflagged))
logger.debug("refresh_hourly36flagged: %s ; refresh_hourly10flagged: %s" %
(refresh_hourly36flagged, refresh_hourly10flagged))
logger.debug("refresh_forecastflagged: %s ; refresh_almanacflagged: %s" %
(refresh_forecastflagged, refresh_almanacflagged))
logger.debug("refresh_sundataflagged: %s ; refresh_tidedataflagged: %s" %
(refresh_sundataflagged, refresh_tidedataflagged))
logger.debug("refresh_hurricanedataflagged: %s ; refresh_yesterdaydataflagged: %s" %
(refresh_hurricanedataflagged, refresh_yesterdaydataflagged))
if checkforUpdates == True:
spinner.stop()
spinner.start(text='Checking for updates...')
reader2 = codecs.getreader("utf-8")
try:
versioncheck = requests.get("https://raw.githubusercontent.com/o355/"
+ "pyweather/master/updater/versioncheck.json")
versionJSON = json.loads(versioncheck.text)
version_buildNumber = float(versionJSON['updater']['latestbuild'])
logger.debug("reader2: %s ; versioncheck: %s" %
(reader2, versioncheck))
if jsonVerbosity == True:
logger.debug("versionJSON: %s" % versionJSON)
logger.debug("version_buildNumber: %s" % version_buildNumber)
version_latestVersion = versionJSON['updater']['latestversion']
version_latestURL = versionJSON['updater']['latesturl']
version_latestFileName = versionJSON['updater']['latestfilename']
version_latestReleaseDate = versionJSON['updater']['releasedate']
logger.debug("version_latestVersion: %s ; version_latestURL: %s"
% (version_latestVersion, version_latestURL))
logger.debug("version_latestFileName: %s ; version_latestReleaseDate: %s"
% (version_latestFileName, version_latestReleaseDate))
if buildnumber < version_buildNumber:
# Print if we're out of date.
logger.info("PyWeather is not up to date.")
print("PyWeather is not up to date. You have version " + buildversion +
", and the latest version is " + version_latestVersion + ".")
print("")
except:
spinner.fail(text="Couldn't check for PyWeather updates!")
print("")
spinner.start(text="Loading PyWeather...")
print("Couldn't check for updates. Make sure raw.githubusercontent.com is unblocked on your network,",
"and that you have a working internet connection.", sep="\n")
# Define about variables here.
logger.info("Defining about variables...")
about_buildnumber = "63"