class PagesTest(unittest.TestCase): def __init__(self, method_name): super().__init__(method_name) self._toc = Pages(SystemConfig.pages_path()) def test_page_filename(self): self.assertEqual(Pages.page_filename("Somewhere"), "Somewhere.txt") def test_path_to_page(self): path = self._toc.page_path("Junk") self.assertEqual(path, "pages/Junk.txt") def test_page_wiki_exists(self): self.assertTrue(self._toc.word_matches_a_page("Wiki")) def test_lower_case_wiki_does_exist(self): self.assertTrue(self._toc.word_matches_a_page("wiki")) def test_nothing_does_not_exist(self): self.assertFalse(self._toc.word_matches_a_page("Nothing")) def test_pages_are_in_all_pages(self): pages = self._toc.all_page_filenames() self.assertIn("Wiki.txt", pages) self.assertIn("Nelson.txt", pages) self.assertIn("Cunningham.txt", pages)
def generate_wiki(): """Reads each page in the pages directory and writes a markup page in the docs directory that will contain text that will link to other pages if they match the words. Also creates a table of contents .""" pages = Pages(SystemConfig.pages_path()) index_file = open("{path}/index.md".format(path=SystemConfig.docs_path()), "w+") index_file.write("# Table of Contents\n") for page_filename in pages.all_page_filenames(): contents = read_contents(page_filename) write_contents(contents, page_filename, pages) write_to_index(page_filename, index_file) index_file.close()
class TestPages(unittest.TestCase): def setUp(self): self.pages = Pages() def test_pages_list_all(self): num = len(self.pages.getAll()) self.assertTrue(num>0) def test_page_get(self): page = Page(PAGE_NAME) self.assertEqual(PAGE_NAME, page.name) def test_page_pics(self): page = Page(PAGE_NAME) self.assertTrue(len(page.pics)>0) def test_first_page(self): page = self.pages.first_page self.assertEqual(page.name, PAGE_NAME) def test_order_list(self): page_list = self.pages.list page_names_list = [p.name for p in page_list] self.assertEqual([PAGE_NAME, PAGE_NAME2], page_names_list[0:2])
def before_scenario(self, context, scenario): super().before_scenario(context, scenario) context.base_e2e_url = os.getenv('E2E_URL') context.logger.info(f'Base E2E URL is: {context.base_e2e_url}') context.logger.info('Starting browser') context.driver = create_webdriver() context.pages = Pages(context)
def getData(url, file, limit): results = Pages.getPages(url, limit) with open(file, mode='w') as csv_file: # sets up csv file writer = csv.writer(csv_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) # creates columns writer.writerow([ 'date', 'abstract', 'rating', 'workLifeBalance', 'cultureAndValues', 'careerOpportunities', 'compensationAndBenefits', 'seniorManagement', 'authorJobTitle', 'tenure', 'pro', 'con' ]) # adds reviews for review in results: writer.writerow([ review.date, review.summary, review.rating, review.workLifeBalance, review.cultureAndValues, review.careerOpportunities, review.compensationAndBenefits, review.seniorManagement, review.authorJobTitle, review.mainText, review.pro, review.con ])
def __init__(self, access_token=''): self.Account = Account(access_token=access_token) self.Apps = Apps(access_token=access_token) self.Audio = Audio(access_token=access_token) self.Auth = Auth(access_token=access_token) self.Board = Board(access_token=access_token) self.Database = Database(access_token=access_token) self.Docs = Docs(access_token=access_token) self.Other = Other(access_token=access_token) self.Fave = Fave(access_token=access_token) self.Friends = Friends(access_token=access_token) self.Gifts = Gifts(access_token=access_token) self.Groups = Groups(access_token=access_token) self.Likes = Likes(access_token=access_token) self.Market = Market(access_token=access_token) self.Messages = Messages(access_token=access_token) self.Newsfeed = Newsfeed(access_token=access_token) self.Notes = Notes(access_token=access_token) self.Notifications = Notifications(access_token=access_token) self.Pages = Pages(access_token=access_token) self.Photos = Photos(access_token=access_token) self.Places = Places(access_token=access_token) self.Polls = Polls(access_token=access_token) self.Search = Search(access_token=access_token) self.Stats = Stats(access_token=access_token) self.Status = Status(access_token=access_token) self.Storage = Storage(access_token=access_token) self.Users = Users(access_token=access_token) self.Utils = Utils(access_token=access_token) self.Video = Video(access_token=access_token) self.Wall = Wall(access_token=access_token) self.Widgets = Widgets(access_token=access_token)
def main(): display = Screen('marvinconfig.txt', parser) menu = Pages('marvinconfig.txt', parser) artifacts = Items('marvinconfig.txt', parser) players = Users('marvinconfig.txt', parser) universe = Devices('marvinconfig.txt', parser) while True: '''TODO:
def test_page(): print('Debug: Page-') page = Pages(['Timeline1', 'Timeline2'], 'button') print('Page: Full page- PASSED ', page.get_items()) page2 = Pages(None, None) print('Page: Empty page- PASSED ', page2.get_items()) x = [str(x) for x in range(20)] page3 = Pages(x, 'button') print('Page: 11+ pages- PASSED ', page3.get_items())
def before_scenario(self, context, scenario): super().before_scenario(context, scenario) desired_caps = { 'deviceName': os.getenv('DEVICE_NAME'), 'fullReset': os.getenv('FULL_RESET'), 'app': os.getenv('APP_PATH'), 'platformName': os.getenv('PLATFORM_NAME'), 'appPackage': os.getenv('APP_PACKAGE'), 'appActivity': os.getenv('APP_ACTIVITY'), 'automationName': os.getenv('AUTOMATION_NAME') } context.driver = webdriver.Remote(os.getenv('MOBILE_ADDRESS'), desired_caps) context.driver.implicitly_wait(5) context.pages = Pages(context)
def main(): pygame.init() pygame.mixer.init() # Groesse fuer das Fenster festlegen screen = pygame.display.set_mode((DISPLAY_WIDTH, DISPLAY_HEIGHT)) # Standardmaessig mit Title Seite anfangen game_state = GameState.TITLE player = Player() # Aufrufen der Logik, die die Pages aufruft while True: game_state = Pages().game_state_logic(game_state, screen, player) if game_state == game_state.QUIT: pygame.quit() return
def add_timelines_to_dict(self): # loop through the split up timeline list and create buttons # for each timeline. Every new list is a new page. # example data- {'1': {'1': (...button...} # '2': {'1': {...button...} pageCounter = 1 for i in self.splitTimelineList: buttonPages = Pages( i, 'buttons') # passing in buttons so it creates a button page actionPages = Pages( i, 'actions') # passing in actions so it creates an action page self.dictOfPages[str(pageCounter)] = buttonPages.get_items() self.dictOfActionPages[str(pageCounter)] = actionPages.get_items() pageCounter += 1 return
import config # Setup config.init() Model.init(config) Views.init(config) JWT.init(config) app = Flask('Note Taker') api = API.create(config) # REST interface app.register_blueprint(api, url_prefix='/api') pages = Pages.create(config) # Views app.register_blueprint(pages) Markdown(app) # Run flask app if __name__ == "__main__": # Setup debug option debug = False if config.get('app.debug'): app.jinja_env.auto_reload = True app.config['TEMPLATES_AUTO_RELOAD'] = True debug = True # Setup sessions
def test_page_filename(self): self.assertEqual(Pages.page_filename("Somewhere"), "Somewhere.txt")
def button(self, text, x, y, width, height, inactive_color, active_color, action=None, size="small", text_color=(0, 0, 0)): """ Tworzy przyciski. :param text: tekst widniejący na przycisku, :param x: wartość z lewego górnego przycisku, :param y: wartość y lewego górnego roku przycisku, :param width: szerokość przycisku, :param height: wysokość przycisku, :param inactive_color: kolor nieaktywnego przycisku, :param active_color: kolor po najechaniu kursorem na przycisk, :param action: akcja jak ma się wykonać po naciśnięciu przycisku, :param size: rozmiar czcionki, :param text_color: kolor tekst. """ #pozycja kursora cur = pygame.mouse.get_pos() #kliknięcie myszką click = pygame.mouse.get_pressed() if x + width > cur[0] > x and y + height > cur[1] > y: pygame.draw.rect(self.screen, active_color, (x, y, width, height)) if click[0] == 1 and action != None: #opcje uruchomienia poszczególnych plansz if action == "board1": self.board1 = True self.board2 = False self.board3 = False if action == "board2": self.board2 = True self.board1 = False self.board3 = False if action == "board3": self.board3 = True self.board1 = False self.board2 = False #parametry deski w zależności od wybranego rozmiaru if action == "short_paddle": self.paddle_width = 70 if action == "medium_paddle": self.paddle_width = 100 if action == "long_paddle": self.paddle_width = 200 #parametry piłki w zależności od wybranego rozmiaru if action == "small_ball": self.ball_width = 18 self.ball_height = 15 self.check = 35 if action == "medium_ball": self.ball_width = 30 self.ball_height = 25 self.check = 40 if action == "big_ball": self.ball_width = 50 self.ball_height = 40 self.check = 45 if action == "play": #uruchomienie wybranych opcji z menu if self.board1 == True and self.paddle_width == 0 and self.ball_width == 0: self.sprites(self.plansza1()) elif self.board1 == True and self.paddle_width != 0 and self.ball_width == 0: self.sprites(self.plansza1(), self.paddle_width) elif self.board1 == True and self.paddle_width == 0 and self.ball_width != 0: self.sprites(self.plansza1(), ball_width=self.ball_width, ball_height=self.ball_height) elif self.board1 == True and self.paddle_width != 0 and self.ball_width != 0: self.sprites(self.plansza1(), self.paddle_width, self.ball_width, self.ball_height) elif self.board2 == True and self.paddle_width == 0 and self.ball_width == 0: self.sprites(self.plansza2()) elif self.board2 == True and self.paddle_width != 0 and self.ball_width == 0: self.sprites(self.plansza2(), self.paddle_width) elif self.board2 == True and self.paddle_width == 0 and self.ball_width != 0: self.sprites(self.plansza2(), ball_width=self.ball_width, ball_height=self.ball_height) elif self.board2 == True and self.paddle_width != 0 and self.ball_width != 0: self.sprites(self.plansza2(), self.paddle_width, self.ball_width, self.ball_height) elif self.board3 == True and self.paddle_width == 0 and self.ball_width == 0: self.sprites(self.plansza3()) elif self.board3 == True and self.paddle_width != 0 and self.ball_width == 0: self.sprites(self.plansza3(), self.paddle_width) elif self.board3 == True and self.paddle_width == 0 and self.ball_width != 0: self.sprites(self.plansza3(), ball_width=self.ball_width, ball_height=self.ball_height) elif self.board3 == True and self.paddle_width != 0 and self.ball_width != 0: self.sprites(self.plansza3(), self.paddle_width, self.ball_width, self.ball_height) elif self.board1 == False and self.board2 == False and self.board3 == False and self.paddle_width == 0 and self.ball_width == 0: self.plansza1() self.sprites() elif self.board1 == False and self.board2 == False and self.board3 == False and self.paddle_width != 0 and self.ball_width == 0: self.plansza1() self.sprites(self.paddle_width) elif self.board1 == False and self.board2 == False and self.board3 == False and self.paddle_width == 0 and self.ball_width != 0: self.plansza1() self.sprites(ball_width=self.ball_width, ball_height=self.ball_height) elif self.board1 == False and self.board2 == False and self.board3 == False and self.paddle_width != 0 and self.ball_width != 0: self.plansza1() self.sprites(paddle_width=self.paddle_width, ball_width=self.ball_width, ball_height=self.ball_height) Functions.reset_ball(self) self.gameLoop() if action == "next": Pages.second_options(self) if action == "about author": Pages.about_author(self) if action == "quit": Functions.invite(self) if action == "back to menu": Pages.start(self) if action == "options": self.options() if action == "back to options": self.options() else: pygame.draw.rect(self.screen, inactive_color, (x, y, width, height)) Functions.text_to_button(self, text, text_color, x, y, width, height, size)
def __init__(self): #Inicjalizacja PyGame self.screen_width = 800 self.screen_height = 600 self.screen_size = (self.screen_width, self.screen_height) #kolory self.black = (0, 0, 0) self.white = (255, 255, 255) self.light_grey = (179, 179, 179) self.grey = (128, 128, 128) self.dark_grey = (115, 115, 115) #zmienne definiowane w celu utzryamania stałej prędkości piłki self.start_vel_x = 4 self.start_vel_y = 4 self.velocity = self.start_vel_x**2 + self.start_vel_y**2 #zmienne potrzebne do zmiany parametrów self.board1 = False self.board2 = False self.board3 = False self.paddle_width = 0 self.ball_width = 0 self.check = 40 #licznik żyć self.live_counter = 3 #zdjęcia planszy self.board1_image = pygame.image.load("data/board1.png") self.board1_image = pygame.transform.scale(self.board1_image, (225, 170)) self.board2_image = pygame.image.load("data/board2.png") self.board2_image = pygame.transform.scale(self.board2_image, (225, 170)) self.board3_image = pygame.image.load("data/board3.png") self.board3_image = pygame.transform.scale(self.board3_image, (225, 170)) self.background = pygame.image.load("data/background.jpg") pygame.init() #dźwięki w grze self.sound_killed_bricks = Functions.loadSound(self, "wood_knock.wav") self.sound_bounced_ball = Functions.loadSound(self, "paddle_bound.wav") self.sound_start = Functions.loadSound(self, "start.wav") self.sound_game = Functions.loadSound(self, "game.wav") self.sound_loose = Functions.loadSound(self, "loose_sound.wav") self.sound_victory = Functions.loadSound(self, "victory.wav") #czcionki self.smallfont = pygame.font.SysFont("comicsansms", 25) self.mediumfont = pygame.font.SysFont("comicsansms", 38) self.bigfont = pygame.font.SysFont("comicsansms", 50) self.largefont = pygame.font.SysFont("comicsansms", 70) self.victoryfont = pygame.font.SysFont("comicsansms", 90) #Inicializacja okna self.screen = pygame.display.set_mode(self.screen_size) pygame.display.set_caption("Arkanoid") #Inicjalizacja grupy dla planszy self.BlocksSprite = pygame.sprite.Group() #Inicjalizacja rozszerzeń self.AddSpeedSprite = pygame.sprite.Group() self.SubstractSpeedSprite = pygame.sprite.Group() #uruchomienie strony startowej Pages.start(self) Functions.reset_ball(self) self.gameLoop()
def gameLoop(self): """Pętla gry właściwej.""" self.sound_start.stop() self.sound_game.play() self.clock = pygame.time.Clock() self.delta = 0.0 self.max_tps = 100.0 self.exit = False self.gameover = False while not self.exit: #dzięlki temu zapewniam tą samą szybkość obiektów niezależnie od możliwości danego komputera self.delta += self.clock.tick() / 1000.0 while self.delta > 1 / self.max_tps: self.delta -= 1 / self.max_tps for event in pygame.event.get(): if event.type == pygame.QUIT: self.exit = True elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: self.exit = True if event.key == pygame.K_SPACE: self.ball.y_velocity = -4 self.ball.x_velocity = 0 keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: self.paddle.rect.x += -self.paddle.speed if keys[pygame.K_RIGHT]: self.paddle.rect.x += self.paddle.speed elif keys[pygame.K_p]: self.sound_game.stop() self.pause() self.clock = pygame.time.Clock() #przegrana if self.ball.rect.centery > self.screen_height - self.check: Functions.reset_ball(self) self.sound_game.stop() if self.live_counter == 1: self.sound_loose.play() self.gameover = True else: self.ball.rect.top = self.screen_height - 100 self.ball.rect.centerx = self.screen_width / 2 self.paddle.rect.left = int(self.screen_width / 2 - self.paddle_width / 2) self.paddle.rect.top = int(self.screen_height - 30) self.sound_game.play() time.sleep(1) self.live_counter -= 1 self.update() #zderzenie piłki i bloków for hit in pygame.sprite.groupcollide(self.BallSprite, self.BlocksSprite, 0, 1): self.sound_killed_bricks.play() self.ball.y_velocity = -self.ball.y_velocity self.killed_blocks = self.counter - len(self.BlocksSprite) #przspieszenie deski po zderzeniu pilki z rozszerzeniem for hit in pygame.sprite.groupcollide(self.BallSprite, self.AddSpeedSprite, 0, 1): self.ball.y_velocity = -self.ball.y_velocity self.paddle.speed = 10 # przspieszenie deski po zderzeniu pilki z rozszerzeniem for hit in pygame.sprite.groupcollide( self.BallSprite, self.SubstractSpeedSprite, 0, 1): self.ball.y_velocity = -self.ball.y_velocity self.paddle.speed = 4 #zwycięstwo if len(self.BlocksSprite) == 0: self.sound_game.stop() self.sound_victory.play() self.live_counter = 3 Pages.victory(self) # zderzenie piłki i deski for hit in pygame.sprite.groupcollide(self.PaddleSprite, self.BallSprite, 0, 0): self.sound_bounced_ball.play() # ustawienie różnych kątów odbicia piłki w zależności od miejsca jej odbicia na desce if (self.paddle.get_pos() - self.paddle_width * 0.1 ) <= self.ball.get_pos() <= (self.paddle.get_pos() + self.paddle_width * 0.1): self.ball.x_velocity = 0 self.ball.y_velocity = -Functions.calculate_velocity( self, self.start_vel_y**2 + self.ball.x_velocity**2, 0) elif self.paddle.get_pos() - self.paddle_width * 0.5 - ( self.ball_width / 2) < self.ball.get_pos() < self.paddle.get_pos( ) - self.paddle_width * 0.3: self.ball.x_velocity = -self.start_vel_x self.ball.y_velocity = -self.ball.y_velocity elif self.paddle.get_pos( ) + self.paddle_width * 0.3 <= self.ball.get_pos( ) < self.paddle.get_pos() + self.paddle_width * 0.5 + ( self.ball_width / 2): self.ball.x_velocity = self.start_vel_x self.ball.y_velocity = -self.ball.y_velocity elif self.paddle.get_pos( ) - self.paddle_width * 0.3 <= self.ball.get_pos( ) < self.paddle.get_pos() - self.paddle_width * 0.1: self.ball.x_velocity = -2 self.ball.y_velocity = Functions.calculate_velocity( self, self.velocity, -2) self.ball.y_velocity = -self.ball.y_velocity elif self.paddle.get_pos( ) + self.paddle_width * 0.1 < self.ball.get_pos( ) < self.paddle.get_pos() + self.paddle_width * 0.3: self.ball.x_velocity = 2 self.ball.y_velocity = Functions.calculate_velocity( self, self.velocity, 2) self.ball.y_velocity = -self.ball.y_velocity self.screen.fill(self.black) self.draw() #wysświetla wynik Functions.score(self, self.killed_blocks, self.counter) Functions.lives(self, self.live_counter) pygame.display.update() #pętla obsługująca przegraną while self.gameover == True: self.sound_game.stop() self.screen.fill(self.grey) Functions.message(self, "Game over", self.white, y_displace=-50, size="large") Functions.message(self, "Press M back to menu, or Q to quit", self.white, y_displace=50) pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: self.exit = True self.gameover = False if event.key == pygame.K_m: Game() if event.key == pygame.K_ESCAPE: pygame.quit() quit() Functions.invite(self)
def __init__(self, method_name): super().__init__(method_name) self._toc = Pages(SystemConfig.pages_path())
def setUp(self): self.pages = Pages()
def test_sentence_with_page_match_includes_markup_link(self): toc = Pages(path_to_pages="") toc.word_matches_a_page = return_true_if_param_is_junk rend = PageRenderer(toc=toc) self.assertEqual("Stuff is [Junk](junk.md).", rend.transform("Stuff is Junk."))
def test_sentence_without_a_word_matching_a_page_is_unchanged(self): toc = Pages(path_to_pages="") toc.word_matches_a_page = MagicMock(return_value=False) rend = PageRenderer(toc=toc) sentence = "A cow jumps over 3 moons, so it must be on Jupiter? I think so. " self.assertEqual(sentence, rend.transform(sentence))
def __init__(self): # detect args parser = OptionParser() parser.add_option("-d", "--debug", dest="debug", action="store_true", help="set debug mode", default=False) parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose mode", default=False) parser.add_option("-p", "--page", dest="page", help="specify a page to handle") parser.add_option("--onepage", dest="onepage", action="store_true", help="only handle a single page (similar to `--pages=1')", default=False) parser.add_option("--task", dest="task", help="run builtin task (use `--task=help' for list of tasks)") parser.add_option("--pages", dest="pagestorun", help="number of pages to handle") parser.add_option("-s", "--search", dest="search", help="search string") parser.add_option("-t", "--time", dest="time", help="set time in format YYYY-MM-DDTHH:MM:SSZ") parser.add_option("--titlesearch", dest="titlesearch", action="store_true", help="search in titles rather than text", default=False) parser.add_option("--writetime", dest="writetime", action="store_true", help="write timestamp at end of run, even if other variables would disable that", default=False) parser.add_option("-r", "--ref", "--loadref", dest="loadref", action="store_true", help="force appearance reference load from wiki", default=False) parser.add_option("--localref", dest="localref", action="store_true", help="force appearance reference to be loaded locally", default=False) parser.add_option("--runtasks", dest="runtasks", action="store_true", help="force run tasks", default=False) parser.add_option("--changes", dest="changes", help="maximum recent changes to run") parser.add_option("--nochanges", dest="nochanges", action="store_true", help="don't check recent changes", default=False) parser.add_option("--donotfixpages", dest="donotfixpages", action="store_true", help="no page cleanup", default=False) parser.add_option("--donotrunpool", dest="donotrunpool", action="store_true", help="don't run changes for the pool", default=False) (options, args) = parser.parse_args() # set debug mode self.debugmode = options.debug self.verbose = options.verbose self.api = Api(debug=self.debugmode, server="theinfosphere.org") self.poolapi = Api(debug=self.debugmode, server="pool.theinfosphere.org") if self.debugmode: self.log("==== Debug mode!") if options.task!=None: # oh noes, we need to run a builtin task, so we should not run # regular tasks taskmanager = Taskmanager(debug=self.debugmode, api=self.api, verbose=self.verbose) if options.task == 'help': print taskmanager.help_response() else: self.log("Builtin task run...") if self.api.login(userdata.username, userdata.password): if not taskmanager.run_task(options.task): self.log("Task `%s' did not run properly or does not exist." % options.task) else: self.log("Could not log in.") self.writelog() else: if not options.nochanges: self.changes = Changes(debug=self.debugmode, api=self.api, verbose=self.verbose) if options.changes != None: self.changes.maximum = options.changes self.runtasks = options.runtasks self.pages = Pages(debug=self.debugmode, api=self.api, verbose=self.verbose) self.pages.singlepage = self.page = options.page pagestorun = 0 if options.onepage: pagestorun = 1 if options.pagestorun != None: pagestorun = options.pagestorun self.pages.pagestorun = self.pagestorun = pagestorun self.pages.search = self.search = options.search self.pages.titlesearch = self.titlesearch = options.titlesearch if options.time!=None: try: time.strptime(options.time, "%Y-%m-%dT%H:%M:%SZ") self.ts = options.time self.log("Using input time of `%s'." % self.ts) except ValueError: self.log("Input time given `%s' does not match format; ignoring." % self.ts) self.ts = None if self.debugmode or self.search!=None or self.pagestorun==1 or self.page!=None or self.ts!=None: # if any of these are the case, then writing a new time stamp could # mess up future runs self.writetime = False if options.writetime: # unless of course, it is forced by the user self.writetime = True self.pages.ar.loadref = options.loadref self.pages.ar.localref = options.localref # insure the api knows, so it won't make edits if debug mode if self.api.login(userdata.username, userdata.password): self.log("Logged in successfully.") if self.check_for_lock(): self.initiate() if not options.nochanges: self.changes.set_ts(self.ts) self.pages.set_ts(self.ts) if self.runtasks or (self.pagestorun==0 and self.page == None): tasks = Tasks(self.debugmode, self.api, self.verbose, self.pages) self.log_obtain(tasks) if not options.nochanges: self.changes.handle_changes() self.log_obtain(self.changes) else: self.log("Not running recent changes checking...") if not options.donotfixpages: self.pages.routine_run() else: self.log("Not running page fixing...") self.log_obtain(self.pages) if not options.donotrunpool: self.images = Images(debug=self.debugmode, api=self.api, verbose=self.verbose, poolapi=self.poolapi) self.images.routine_job(self.ts) self.log_obtain(self.images) else: self.log("Not running through the pool...") self.finish() else: self.log("Could not log in.") self.writelog()
class Svipbot(object): api = None poolapi = None loglines = [] debugmode = False writetime = True oldts = None ts = None newts = None pages = None images = None def check_for_lock(self): if os.path.exists("botlock"): self.log("Botlock file exists.") return False self.log("No botlock.") return True def log(self, msg=None, view=True): if msg==None: return self.loglines else: self.loglines.append(msg) if (self.debugmode or self.verbose) and view: print msg def log_obtain(self, obj): if obj==None: return for l in obj.get_log(): self.log(l, False) obj.clear_log() def initiate(self): f = open('botlock', 'w') f.write('x') f.close() self.log("Wrote botlock.") try: f = open('time', 'r') self.ts = f.read().strip() self.log("Found time of `%s'." % self.ts) f.close() except IOError: self.ts = None # just to make sure # create a timestamp now, because the edits may take time, and someone could # make an edit in between, and we want to catch that. self.newts = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) def finish(self): # current time if self.newts==None: ts = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) else: ts = self.newts if self.writetime: f = open('time', 'w') f.write(ts) f.close() self.log("Wrote timestamp of `%s'." % ts) # remove botlock os.remove("botlock") self.log("Removed botlock") def writelog(self): if not self.debugmode: # log fn = "logs/runlog-%s" % time.strftime("%Y%m%dT%H%M", time.gmtime()) log = open(fn, 'w') log.writelines([unicode("%s\n"%s).encode('utf-8') for s in self.log()]) log.close() def __init__(self): # detect args parser = OptionParser() parser.add_option("-d", "--debug", dest="debug", action="store_true", help="set debug mode", default=False) parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose mode", default=False) parser.add_option("-p", "--page", dest="page", help="specify a page to handle") parser.add_option("--onepage", dest="onepage", action="store_true", help="only handle a single page (similar to `--pages=1')", default=False) parser.add_option("--task", dest="task", help="run builtin task (use `--task=help' for list of tasks)") parser.add_option("--pages", dest="pagestorun", help="number of pages to handle") parser.add_option("-s", "--search", dest="search", help="search string") parser.add_option("-t", "--time", dest="time", help="set time in format YYYY-MM-DDTHH:MM:SSZ") parser.add_option("--titlesearch", dest="titlesearch", action="store_true", help="search in titles rather than text", default=False) parser.add_option("--writetime", dest="writetime", action="store_true", help="write timestamp at end of run, even if other variables would disable that", default=False) parser.add_option("-r", "--ref", "--loadref", dest="loadref", action="store_true", help="force appearance reference load from wiki", default=False) parser.add_option("--localref", dest="localref", action="store_true", help="force appearance reference to be loaded locally", default=False) parser.add_option("--runtasks", dest="runtasks", action="store_true", help="force run tasks", default=False) parser.add_option("--changes", dest="changes", help="maximum recent changes to run") parser.add_option("--nochanges", dest="nochanges", action="store_true", help="don't check recent changes", default=False) parser.add_option("--donotfixpages", dest="donotfixpages", action="store_true", help="no page cleanup", default=False) parser.add_option("--donotrunpool", dest="donotrunpool", action="store_true", help="don't run changes for the pool", default=False) (options, args) = parser.parse_args() # set debug mode self.debugmode = options.debug self.verbose = options.verbose self.api = Api(debug=self.debugmode, server="theinfosphere.org") self.poolapi = Api(debug=self.debugmode, server="pool.theinfosphere.org") if self.debugmode: self.log("==== Debug mode!") if options.task!=None: # oh noes, we need to run a builtin task, so we should not run # regular tasks taskmanager = Taskmanager(debug=self.debugmode, api=self.api, verbose=self.verbose) if options.task == 'help': print taskmanager.help_response() else: self.log("Builtin task run...") if self.api.login(userdata.username, userdata.password): if not taskmanager.run_task(options.task): self.log("Task `%s' did not run properly or does not exist." % options.task) else: self.log("Could not log in.") self.writelog() else: if not options.nochanges: self.changes = Changes(debug=self.debugmode, api=self.api, verbose=self.verbose) if options.changes != None: self.changes.maximum = options.changes self.runtasks = options.runtasks self.pages = Pages(debug=self.debugmode, api=self.api, verbose=self.verbose) self.pages.singlepage = self.page = options.page pagestorun = 0 if options.onepage: pagestorun = 1 if options.pagestorun != None: pagestorun = options.pagestorun self.pages.pagestorun = self.pagestorun = pagestorun self.pages.search = self.search = options.search self.pages.titlesearch = self.titlesearch = options.titlesearch if options.time!=None: try: time.strptime(options.time, "%Y-%m-%dT%H:%M:%SZ") self.ts = options.time self.log("Using input time of `%s'." % self.ts) except ValueError: self.log("Input time given `%s' does not match format; ignoring." % self.ts) self.ts = None if self.debugmode or self.search!=None or self.pagestorun==1 or self.page!=None or self.ts!=None: # if any of these are the case, then writing a new time stamp could # mess up future runs self.writetime = False if options.writetime: # unless of course, it is forced by the user self.writetime = True self.pages.ar.loadref = options.loadref self.pages.ar.localref = options.localref # insure the api knows, so it won't make edits if debug mode if self.api.login(userdata.username, userdata.password): self.log("Logged in successfully.") if self.check_for_lock(): self.initiate() if not options.nochanges: self.changes.set_ts(self.ts) self.pages.set_ts(self.ts) if self.runtasks or (self.pagestorun==0 and self.page == None): tasks = Tasks(self.debugmode, self.api, self.verbose, self.pages) self.log_obtain(tasks) if not options.nochanges: self.changes.handle_changes() self.log_obtain(self.changes) else: self.log("Not running recent changes checking...") if not options.donotfixpages: self.pages.routine_run() else: self.log("Not running page fixing...") self.log_obtain(self.pages) if not options.donotrunpool: self.images = Images(debug=self.debugmode, api=self.api, verbose=self.verbose, poolapi=self.poolapi) self.images.routine_job(self.ts) self.log_obtain(self.images) else: self.log("Not running through the pool...") self.finish() else: self.log("Could not log in.") self.writelog()