Example #1
0
def parse_crontab(filename):
	"""
	Get a file descriptor on filename and
	create feeds and groups for API keys therein.
	"""
	def log(message):
		print message
	# read filename into a string named crontab
	try:
		fd = open(filename, "r")
	except OSError:
		print "Error opening %s" % filename
		raise SystemExit
	crontab = fd.read()
	fd.close()

	# keep a resident api key on hand
	key = None

	for i, line in enumerate(crontab.split('\n')):

		# Set the APIKey we're working with when we find a line starting
		# with apikey:
		if line.startswith("apikey:"):
			if ' ' in line:
				key_str = line.split()[1]
				key = APIKey.query.filter(APIKey.key == key_str).first()
			if not key:
				print 'Malformed or unknown API key at line %i in %s: %s' % (i+1, filename, line)
				raise SystemExit
			else:
				print 'Using API key "%s".' % key.name

		if line.startswith("http"):
			feed = {'active': True}

			# Grab the URL and set the string to the remainder
			feed['url'] = line.split().pop(0)
			line = ' '.join(line.split()[1:])

			# Grab names and groups
			names = spaceparse(line)
			if not names:
				print "Error parsing feed or group name at line %i in %s: %s" % (i+1, filename, line)
				continue
			feed['name'], group = names[:2]

			# The schedule should be the last five items
			schedule = line.split()[-5:]
			try:
				parse_timings(schedule)
			except Exception, e:
				print "Error parsing schedule at line %i in %s: %s" % (i+1, filename, e.message)
				continue

			feed['schedule'] = ' '.join(schedule)

			create_feed(log, db, key, group, feed)
Example #2
0
 def parse_args(self, args):
     body = {}
     parsed = spaceparse(args)
     args = args.split()
     for i in args:
         try:
             x=i.split('=')
             if type(parsed) == dict and not x[0] in parsed:
                 parsed[x[0]] = x[1]
             else:
                 body[x[0]] = x[1]
         except: continue
     if type(parsed) == dict: body = parsed
     return body
Example #3
0
 def parse_args(self, args):
     body = {}
     parsed = spaceparse(args)
     args = args.split()
     for i in args:
         try:
             x = i.split('=')
             if type(parsed) == dict and not x[0] in parsed:
                 parsed[x[0]] = x[1]
             else:
                 body[x[0]] = x[1]
         except:
             continue
     if type(parsed) == dict: body = parsed
     return body