-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathinit.py
More file actions
27 lines (22 loc) · 825 Bytes
/
init.py
File metadata and controls
27 lines (22 loc) · 825 Bytes
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
# coding: utf-8
import io
import os
from subprocess import Popen
# https://devcenter.heroku.com/articles/runtime-principles#web-servers
# The port to bind to is assigned by Heroku as the PORT environment variable.
PORT = os.environ['PORT']
with io.open("scrapyd.conf", 'r+', encoding='utf-8') as f:
f.read()
f.write(u'\nhttp_port = %s\n' % PORT)
# Launch LogParser as a subprocess
logs_dir = '/app/logs'
if not os.path.exists(logs_dir):
os.mkdir(logs_dir)
args = ['logparser', '-dir', logs_dir]
args.extend(['--scrapyd_server', '127.0.0.1:%s' % PORT])
args.extend(['--sleep', os.environ.get('PARSE_ROUND_INTERVAL', '10')])
if os.environ.get('ENABLE_TELNET', 'True') == 'False':
args.extend(['--disable_telnet'])
if os.environ.get('VERBOSE', 'False') == 'True':
args.extend(['--verbose'])
Popen(args)