summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorAlexis Hildebrandt <afh@surryhill.net>2023-12-04 12:23:56 +0100
committerAlexis Hildebrandt <afh@surryhill.net>2023-12-04 12:23:56 +0100
commit3d22ddc7e67a06d0bdf2994b1ef018bc46e92f34 (patch)
tree287e867ef25bf2ecbaa9364f257aefdfb23ef97f /contrib
parent8bbd3fed06087243861a6d6ec9c58dd8858ab34c (diff)
downloadfork-ledger-3d22ddc7e67a06d0bdf2994b1ef018bc46e92f34.tar.gz
fork-ledger-3d22ddc7e67a06d0bdf2994b1ef018bc46e92f34.tar.bz2
fork-ledger-3d22ddc7e67a06d0bdf2994b1ef018bc46e92f34.zip
Migrate Python scripts to Python 3
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/getquote-uk.py13
-rwxr-xr-xcontrib/ledger-du32
2 files changed, 23 insertions, 22 deletions
diff --git a/contrib/getquote-uk.py b/contrib/getquote-uk.py
index a69d4e7d..0c6c052a 100755
--- a/contrib/getquote-uk.py
+++ b/contrib/getquote-uk.py
@@ -1,7 +1,6 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
+#!/usr/bin/env python3
-import urllib, string, sys
+import urllib, string, sys, os
def download(sym):
url = "http://uk.old.finance.yahoo.com/d/quotes.csv?s="
@@ -13,11 +12,13 @@ def download(sym):
result = float(fields[1])/100
return result
-
+if len(sys.argv) == 1:
+ print(f'USAGE: {os.path.basename(__file__)} SYMBOL', file=sys.stderr)
+ sys.exit(-1)
sym = sys.argv[1]
sym = sym.replace('_', '.')
if sym == '£':
- print '£1.00'
+ print('£1.00')
else:
- try: print "£" +str(download(sym))
+ try: print(f'£ {str(download(sym))}')
except: pass
diff --git a/contrib/ledger-du b/contrib/ledger-du
index 580e916e..fe5a0706 100755
--- a/contrib/ledger-du
+++ b/contrib/ledger-du
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import string
import sys
@@ -9,28 +9,28 @@ from stat import *
from os.path import *
def report_file(path):
- dir_elems = string.split(dirname(path), os.sep)
+ dir_elems = dirname(path).split(os.sep)
if dir_elems[0] == "." or dir_elems[0] == "":
- dir_elems = dir_elems[1 :]
- account = string.join(dir_elems, ":")
+ dir_elems = dir_elems[1 :]
+ account = ":".join(dir_elems)
info = os.stat(path)
- print time.strftime("%Y/%m/%d", time.localtime(info[ST_MTIME])),
+ print(time.strftime("%Y/%m/%d", time.localtime(info[ST_MTIME])))
- print basename(path)
- print " ", account, " ", info[ST_SIZE], "b"
- print " Equity:Files"
- print
+ print(f'''{basename(path)}
+ \t{account} {info[ST_SIZE]}b
+ \tEquity:Files
+ ''')
def find_files(path):
xacts = os.listdir(path)
for xact in xacts:
xact = join(path, xact)
- if not islink(xact):
- if isdir(xact) and xact != "/proc":
- find_files(xact)
- else:
- report_file(xact)
+ if not islink(xact):
+ if isdir(xact) and xact != "/proc":
+ find_files(xact)
+ else:
+ report_file(xact)
args = sys.argv[1:]
if len(args):
@@ -38,12 +38,12 @@ if len(args):
else:
paths = ["."]
-print """
+print("""
C 1.00 Kb = 1024 b
C 1.00 Mb = 1024 Kb
C 1.00 Gb = 1024 Mb
C 1.00 Tb = 1024 Gb
-"""
+""")
for path in paths:
find_files(path)