Skip to content

Commit fca663e

Browse files
committed
Modernize Python 2 code
1 parent e5818cc commit fca663e

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

software/processdump/create_json.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#! /usr/bin/python
22

3+
from __future__ import print_function
34
from slugify import slugify
45
import json
56
import os
@@ -12,21 +13,21 @@
1213
penta_url='https://archive.fosdem.org/2016/schedule/xml'
1314
outdir ='/tmp/jsonfiles'
1415

15-
print "Checking if we have the schedule..."
16+
print("Checking if we have the schedule...")
1617
if os.path.isfile(os.path.basename(penta_url)):
1718
penta = os.path.basename(penta_url)
1819
else:
19-
print "Getting the schedule..."
20+
print("Getting the schedule...")
2021
penta = wget.download(penta_url)
2122

22-
print "Parsing the schedule file..."
23+
print("Parsing the schedule file...")
2324
pentaparse = ET.parse(penta).getroot()
2425

25-
print "Finding the talks to process into json files..."
26+
print("Finding the talks to process into json files...")
2627
talks = pentaparse.findall(".//event")
2728

2829
for talk in talks:
29-
print "Creating relevant file names for this talk..."
30+
print("Creating relevant file names for this talk...")
3031
title = talk.find('title').text
3132
track = talk.find('track').text
3233
slug_track = slugify(track)
@@ -35,9 +36,9 @@
3536
track_dir = outdir + "/"+ slug_track
3637
jsonfilename = slug_title+ '.json'
3738

38-
print "Creating track_dir..."
39+
print("Creating track_dir...")
3940
try:
40-
os.makedirs(track_dir, 0755)
41+
os.makedirs(track_dir, 0o755)
4142
except:
4243
pass
4344

software/processdump/split_video.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#! /usr/bin/python
22

3+
from __future__ import print_function
34
from PIL import Image
45
from PIL import ImageFont
56
from PIL import ImageDraw
@@ -28,21 +29,21 @@
2829
# FIXME. Do something
2930
sys.exit(1)
3031

31-
print "Checking if we have the schedule..."
32+
print("Checking if we have the schedule...")
3233
if os.path.isfile(os.path.basename(penta_url)):
3334
penta = os.path.basename(penta_url)
3435
else:
35-
print "Getting the schedule..."
36+
print("Getting the schedule...")
3637
penta = wget.download(penta_url)
3738

38-
print "Parsing the schedule file..."
39+
print("Parsing the schedule file...")
3940
pentaparse = ET.parse(penta).getroot()
4041
# FIXME Either keep the downloaded penta xml file and make sure it doesn't get downloaded again, or throw it out and always get a fresh one.
4142

42-
print "Finding the talk to process..."
43+
print("Finding the talk to process...")
4344
talk = pentaparse.find(".//event[@id='"+data['event_id']+"']")
4445

45-
print "Creating relevant file names for this talk..."
46+
print("Creating relevant file names for this talk...")
4647
title = talk.find('title').text
4748
track = talk.find('track').text
4849
slug_track = slugify(track)
@@ -60,44 +61,44 @@
6061
postrolltsname = postrollbasename+ '.ts'
6162
finalcut = outdir+ videobasename+ '.mp4'
6263

63-
print "Creating tmpdir"
64+
print("Creating tmpdir")
6465
try:
65-
os.makedirs(tmpdir, 0755)
66+
os.makedirs(tmpdir, 0o755)
6667
except:
6768
pass
6869

69-
print "Creating outdir..."
70+
print("Creating outdir...")
7071
try:
71-
os.makedirs(outdir, 0755)
72+
os.makedirs(outdir, 0o755)
7273
except:
7374
pass
7475

75-
print "Getting list of speakers for this talk..."
76+
print("Getting list of speakers for this talk...")
7677
persons = [p.text for p in talk.find('persons')]
7778
personsline = ''
7879
for p in persons:
7980
personsline += p + ' '
8081

81-
print "Grabbing the part of the video we need..."
82+
print("Grabbing the part of the video we need...")
8283
url = data['url'] + "?start=" + data['start'] + "&end=" + data['end']
8384
filename = wget.download(url,out=nakedvideomp4name)
8485

85-
print "Creating custom preroll image from talk metadata..."
86+
print("Creating custom preroll image from talk metadata...")
8687
img = Image.open("preroll.jpg")
8788
draw = ImageDraw.Draw(img)
8889
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", 64)
8990
draw.text((0, 0),title,(0,0,0),font=font)
9091
draw.text((0, 100),personsline,(0,0,0),font=font)
9192
img.save(prerollimgname)
9293

93-
print "Processing preroll and postroll images into video..."
94+
print("Processing preroll and postroll images into video...")
9495
subprocess.check_call(['ffmpeg', '-y', '-loop', '1' , '-i', prerollimgname, '-c:v', 'libx264', '-r', '25', '-frames:v', '125', prerolltsname])
9596
subprocess.check_call(['ffmpeg', '-y', '-loop', '1' , '-i', "postroll.jpg", '-c:v', 'libx264', '-r', '25', '-frames:v', '125', postrolltsname])
9697

97-
print "Concatenating preroll, video and postroll..."
98+
print("Concatenating preroll, video and postroll...")
9899
subprocess.check_call(['ffmpeg', '-y', '-i', nakedvideomp4name, '-c', 'copy', nakedvideotsname])
99100
concatcommand = 'ffmpeg -y -f mpegts -i "concat:'+prerolltsname+ '|'+ nakedvideotsname+ '|'+ postrolltsname+'" -c copy -bsf:a aac_adtstoasc '+ finalcut
100101
subprocess.check_call(concatcommand, shell=True)
101102

102-
print "Cleaning up temporary directory..."
103+
print("Cleaning up temporary directory...")
103104
shutil.rmtree(tmpdir)

0 commit comments

Comments
 (0)