def create_subscriber(firstname, lastname, email, address, ssn): subscriber = Subscriber() subscriber.first_name = firstname subscriber.last_name = lastname subscriber.email = email subscriber.address = address subscriber.ssn = ssn try: subscriber.save() except Exception as e: print(e) return subscriber
def create_subscribers(num): subscribers = [] for i in range(num): subscriber = Subscriber() subscriber.first_name = fake.first_name() subscriber.last_name = fake.last_name() subscriber.email = fake.email() subscriber.address = fake.address() subscriber.ssn = fake.ssn() subscribers.append(subscriber) return subscribers
def create_book(num): books = [] publishers = Publisher.objects() subscribers = Subscriber.objects() for i in range(num): book = Book() book.title = fake.sentence(nb_words=4) book.author.append(fake.name()) book.pages = fake.pyint(min_value=100, max_value=600) book.publish_date = fake.date() book.publisher = random.choices(publishers)[0] borrow = Borrow() borrow.subscriber = random.choices(subscribers)[0] borrow.start = fake.date_object() borrow.end = borrow.start + datetime.timedelta( days=random.randint(14, 60)) book.borrowing_history.append(borrow) books.append(book) return books
def work(self, entry): if self.watching(entry['domain']): self.data.add_entry(entry) def watching(self, domain): if 'all' in self.domains or (domain is None and 'none' in self.domains): return True return domain in [s.lower() for s in self.domains] if __name__ == "__main__": domains = args.domains.split(' ') bcolors.print_colour("S8: Mysql Stasher\n", bcolors.OKGREEN, bcolors.UNDERLINE) bcolors.print_colour("Stashing: %s domain(s)\n" % ', '.join(domains), bcolors.OKGREEN) bcolors.print_colour("Press Ctrl-C to exit\n", bcolors.OKGREEN) try: data = Data(args) c = Processor(data, domains) s = Subscriber(args.subscription) s.work(c.work) except (KeyboardInterrupt, SystemExit, StopIteration): pass except ConnectionError as err: Data.invalid_connection(err, args) """ TODO ---- Need to be able to filter for event severity and/or event contents """
if os.path.isfile(conf_path): self.read(conf_path) else: self.add_section('base') self.write(open(conf_path, 'w')) bcolors.print_colour("Writing default config to ~/.a8\n", bcolors.OKBLUE, bcolors.BOLD) def check_section(self, section): if not self.has_section(section): self.add_section(section) def get_host(self, section): if not self.has_section(section): self.add_section(section) return dict(self.items(section, True)) if __name__ == "__main__": from data.config import args as db_args bcolors.print_colour("A8: alerting tool\n", bcolors.OKGREEN, bcolors.UNDERLINE) bcolors.print_colour("Press Ctrl-C to exit\n", bcolors.OKGREEN, ) try: data = Data(db_args) p = Processor(data) s = Subscriber() s.work(p.work) except (KeyboardInterrupt, SystemExit): pass
parser.add_argument('-v', '--verbose', action='store_true') args = parser.parse_args() class Processor: def __init__(self, channel): self.destin = redis.Redis(args.host, args.port, socket_connect_timeout=1) self.destin.ping() self.channel = channel def work(self, item): if args.verbose: bcolors.print_colour("Log: %s\n" % item['data'], bcolors.OKGREEN) self.destin.publish(self.channel, item['data']) if __name__ == "__main__": bcolors.print_colour("P8: L8 proxy\n", bcolors.OKGREEN, bcolors.UNDERLINE) bcolors.print_colour('Proxy endpoint: %s:%s\n' % (args.host, args.port), bcolors.OKGREEN) bcolors.print_colour("Press Ctrl-C to exit\n", bcolors.OKGREEN) try: c = Processor(args.subscription) s = Subscriber(args.subscription) s.work_raw(c.work) except redis.ConnectionError as err: bcolors.print_colour('Connection error\n', bcolors.FAIL, bcolors.UNDERLINE) bcolors.print_colour(str(err), bcolors.FAIL) except (KeyboardInterrupt, SystemExit): pass
def get_subscriber_by_ssn(ssn): subscriber = Subscriber.objects(ssn=ssn).first() return subscriber
def get_subscriber_by_name(firstname, lastname): subscriber = Subscriber.objects( Q(first_name=firstname) & Q(last_name=lastname)).first() return subscriber
def get_subscriber_by_id(id): subscriber = Subscriber.objects(id=id).first() return subscriber
def get_subscriber_by_email(email): subscriber = Subscriber.objects(email=email).first() return subscriber