Skip to content

Commit

Permalink
Remove try-catch blocks in python scripts
Browse files Browse the repository at this point in the history
This change stops main script execution in case of
any errors. Previously, the script would tell the
user about the error but continue.
  • Loading branch information
m52go committed Oct 29, 2021
1 parent fef7f96 commit b6f5e9f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 65 deletions.
10 changes: 5 additions & 5 deletions .dao/generate_dashboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ mkdir -p data
# generate cycle burn data

echo -e "Parsing DAO transactions to get burn figures...\n"
python3 utilities/dao-burn/parse-txs.py
python3 utilities/dao-burn/parse-txs.py || exit 2

# generate cycle overview data

echo -e "Compiling overview data for dashboard...\n"
python3 utilities/cycle-overview-data/fetch.py
python3 utilities/cycle-overview-data/fetch.py || exit 2

# generate series for bsq supply chart

echo -e "Generating data series for BSQ supply chart...\n"
python3 utilities/supply-graph-series/generate.py
python3 utilities/supply-graph-series/generate.py || exit 2

head -n 4 ../js/dashboard.js > ../js/dashboard-2.js
less data/highcharts-vars.txt >> ../js/dashboard-2.js
Expand All @@ -26,9 +26,9 @@ mv ../js/dashboard-2.js ../js/dashboard.js
# generate cycle tiles on /dashboard

echo -e "Generating cycle tiles for dashboard page...\n"
python3 utilities/dashboard-tiles/generate.py
python3 utilities/dashboard-tiles/generate.py || exit 2

# generate cycle pages at /dashboard/cycle-n

echo -e "Generating cycle pages...\n"
python3 utilities/cycle-detail-pages/generate.py
python3 utilities/cycle-detail-pages/generate.py || exit 2
29 changes: 6 additions & 23 deletions .dao/utilities/cycle-detail-pages/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,13 @@
import math

overviewFilePath = 'data/cycle-overview-data.json'
overviewPathError = 'Error finding cycle overview file.'

burnFilePath = 'data/dao-burn-cycle.json'
burnPathError = 'Error finding cycle burn file.'

settingsFilePath = 'settings.json'
pathError = 'Error finding DAO tx files...did you put the right path in ' + settingsFilePath + '? You must specify the full path.'

### get overview data

try:
with open( overviewFilePath, 'r' ) as overviewFile:
overview = overviewFile.read()
except:
print( overviewPathError )
sys.exit()
with open( overviewFilePath, 'r' ) as overviewFile:
overview = overviewFile.read()

overviewObj = json.loads(overview)

Expand Down Expand Up @@ -60,12 +51,8 @@ def getFriendlyTxType( txType ):

### get burn data and order it by total fees earned

try:
with open( burnFilePath, 'r' ) as burnFile:
burnData = burnFile.read()
except:
print( burnPathError )
sys.exit()
with open( burnFilePath, 'r' ) as burnFile:
burnData = burnFile.read()

burnDataObj = json.loads(burnData)

Expand All @@ -84,12 +71,8 @@ def getFriendlyTxType( txType ):

### get issuance details from dao results file

try:
with open( settingsFilePath, 'r' ) as settingsFile:
settings = settingsFile.read()
except:
print( pathError )
sys.exit()
with open( settingsFilePath, 'r' ) as settingsFile:
settings = settingsFile.read()

settingsObj = json.loads(settings)
voteResultsPath = settingsObj['daoVoteResultsFile']
Expand Down
18 changes: 4 additions & 14 deletions .dao/utilities/cycle-overview-data/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
timeNow = math.floor( time.time() )

daoCycleBurnDataFilePath = 'data/dao-burn-cycle.json'

settingsFilePath = 'settings.json'
pathError = 'Error finding DAO voting results file...did you put the right path in ' + settingsFilePath + '? You must specify the full path.'

### return cycle start and end blocks from cycle number

Expand All @@ -29,24 +27,16 @@ def getCycleBlocks( cycle ):

### get settings

try:
with open( settingsFilePath, 'r' ) as settingsFile:
settings = settingsFile.read()
except:
print( pathError )
sys.exit()
with open( settingsFilePath, 'r' ) as settingsFile:
settings = settingsFile.read()

settingsObj = json.loads(settings)
daoResultsPath = settingsObj['daoVoteResultsFile']

### get dao burn data

try:
with open( daoCycleBurnDataFilePath, 'r' ) as daoBurnFile:
daoBurnData = daoBurnFile.read()
except:
print( 'Error reading file with DAO burn data.')
sys.exit()
with open( daoCycleBurnDataFilePath, 'r' ) as daoBurnFile:
daoBurnData = daoBurnFile.read()

daoBurnDataObj = json.loads(daoBurnData)

Expand Down
9 changes: 2 additions & 7 deletions .dao/utilities/dao-burn/parse-txs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
dailyResults = {}

settingsFilePath = 'settings.json'
pathError = 'Error finding DAO tx files...did you put the right path in ' + settingsFilePath + '? You must specify the full path.'

resultTemplate = {
'IRREGULAR': {
Expand Down Expand Up @@ -139,12 +138,8 @@ def writeJsonToCsv( timeType, destinationFile, dictionary ):

### get settings

try:
with open( settingsFilePath, 'r' ) as settingsFile:
settings = settingsFile.read()
except:
print( pathError )
sys.exit()
with open( settingsFilePath, 'r' ) as settingsFile:
settings = settingsFile.read()

settingsObj = json.loads(settings)
daoTxPath = settingsObj['daoTxDirectory']
Expand Down
9 changes: 2 additions & 7 deletions .dao/utilities/dashboard-tiles/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
import calendar

overviewFilePath = 'data/cycle-overview-data.json'
pathError = 'Error finding cycle overview file.'

### get overview data

try:
with open( overviewFilePath, 'r' ) as overviewFile:
overview = overviewFile.read()
except:
print( pathError )
sys.exit()
with open( overviewFilePath, 'r' ) as overviewFile:
overview = overviewFile.read()

with open( '../_includes/dao_dashboard_tiles.html', 'w' ) as f:
f.write( '' )
Expand Down
9 changes: 2 additions & 7 deletions .dao/utilities/supply-graph-series/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@
bsqSupply = [2548500, 2620250, 2671850, 2722950, 2769150, 2806330, 2830832, 2868164, 2889799, 2934231, 2971823, 3018665, 3052400, 3272927, 3344765, 3406635, 3520705, 3657480]

overviewFilePath = 'data/cycle-overview-data.json'
pathError = 'Error: could not find cycle overview file.'

### get cycle data from overview file

try:
with open( overviewFilePath, 'r' ) as overview:
overviewData = overview.read()
except:
print( pathError )
sys.exit()
with open( overviewFilePath, 'r' ) as overview:
overviewData = overview.read()

overViewDataObj = json.loads(overviewData)

Expand Down
4 changes: 2 additions & 2 deletions js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ $( document ).ready( function() {
},
yAxis: [{
title: {
text: '',
text: "",

},
labels: {
formatter: function () {
return this.value / 1000000 + 'M';
return this.value / 1000000 + "M";
}
},
gridLineColor: "transparent",
Expand Down

0 comments on commit b6f5e9f

Please sign in to comment.