#!/usr/bin/env python2.6 # # Copyright (C) 2011 by Brian Weck # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php # import utils from cssbot import log, config, style # log = log.getLogger("cssbot") # subreddits = config.getList("cssbot", "subreddits") for subreddit in subreddits: # log.warn("forcing update of stylesheet for %s", subreddit) # get configured values for the subreddit selector = config.get(subreddit, "style_selector") rule = config.get(subreddit, "style_rule") # update the css. stylesheet = style.Stylesheet(subreddit, selector, rule) stylesheet.generate_and_save()
with utils.FileLock("update", timeout=2) as lock: log.debug("got lock") for subreddit in subreddits: # get configured values for the subreddit maxage = config.getInt(subreddit, "maxage") words = config.getList(subreddit, "words") moderators = config.getList(subreddit, "moderators") selector = config.get(subreddit, "style_selector") rule = config.get(subreddit, "style_rule") # setup. expunge = index.Expunge(subreddit, maxage) index = index.Indexer(subreddit, maxage) matcher = process.Matcher(subreddit, words, moderators) # process. expunge.old() index.new() matcher.run() # update the css? if expunge.is_dirty() or matcher.is_dirty(): stylesheet = style.Stylesheet(subreddit, selector, rule) stylesheet.generate_and_save() except utils.FileLockException as e: log.warn("unable to obtain lock, probable cause is another process executing")
#!/usr/bin/env python2.6 # # Copyright (C) 2011 by Brian Weck # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php # import utils from cssbot import log, queue # utils.usage(1, "usage: %s id") thing_id = utils.argv(1) # log = log.getLogger("cssbot.dequeue") # queue = queue.Queue() thing = queue.contains({"data.id": thing_id}) # if we have an item, and up for queueing. if thing and "next_ts" in thing: log.warn("removing item %s from queue", thing_id) queue.dequeue(thing) else: log.error("did not remove thing %s from the queue", thing_id)
#!/usr/bin/env python2.6 # # Copyright (C) 2011 by Brian Weck # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php # import utils from cssbot import log, queue # utils.usage(1, "usage: %s id") thing_id = utils.argv(1) # log = log.getLogger("cssbot.dequeue") # queue = queue.Queue() thing = queue.contains({"data.id":thing_id}) # if we have an item, and up for queueing. if thing and "next_ts" in thing: log.warn("removing item %s from queue", thing_id) queue.dequeue(thing) else: log.error("did not remove thing %s from the queue", thing_id)
try: with utils.FileLock("update", timeout=2) as lock: log.debug("got lock") for subreddit in subreddits: # get configured values for the subreddit maxage = config.getInt(subreddit, "maxage") words = config.getList(subreddit, "words") moderators = config.getList(subreddit, "moderators") selector = config.get(subreddit, "style_selector") rule = config.get(subreddit, "style_rule") # setup. expunge = index.Expunge(subreddit, maxage) index = index.Indexer(subreddit, maxage) matcher = process.Matcher(subreddit, words, moderators) # process. expunge.old() index.new() matcher.run() # update the css? if expunge.is_dirty() or matcher.is_dirty(): stylesheet = style.Stylesheet(subreddit, selector, rule) stylesheet.generate_and_save() except utils.FileLockException as e: log.warn( "unable to obtain lock, probable cause is another process executing")