def get_team(team): """ We're asking user for names and address of the rest of the team, and append that to a list we got from get_main_organizer """ add_team = click.confirm(click.style( "Do you want to add additional team members?", bold=True, fg='yellow'), default=False) i = 1 while add_team: i += 1 name = click.prompt( click.style("First and last name of #{0} member".format(i), bold=True, fg='yellow')) email = click.prompt( click.style("E-mail address of #{0} member".format(i), bold=True, fg='yellow')) if len(name) > 0: team.append({'name': name, 'email': email}) click.echo( "All right, the #{0} team member of Django Girls is {1} ({2})". format(i, name, email)) add_team = click.confirm(click.style( "Do you want to add additional team members?", bold=True, fg='yellow'), default=False) return team
def get_basic_info(): """ Here we're asking the user for: - city - country - date - url - event_email And return all these information. """ click.echo( "Hello there! Let's create new Django Girls event! So exciting!") click.echo("Let's start with some basics.") city = click.prompt(click.style( "What is the name of the city?", bold=True, fg='yellow')) country = click.prompt(click.style( "What is the name of the country?", bold=True, fg='yellow')) date = gather_event_date_from_prompt() url = click.prompt(click.style( "What should be the URL of website? djangogirls.org/xxxx", bold=True, fg='yellow')) event_mail = click.prompt(click.style( "What is the mail adress of the event? [email protected]", bold=True, fg='yellow')) click.echo("Ok, got that! Your new event will happen in {0}, {1} on {2}".format( city, country, date)) return (city, country, date, url, event_mail)
def gather_information(): click.echo("Hello there sunshine! We're gonna copy an event website now.") event = get_event( click.prompt(click.style("First, give me the latest ID of the Event " "object you want to copy", bold=True, fg='yellow')) ) while not event: event = get_event(click.prompt("Wrong ID! Try again")) click.echo("Ok, we're copying {}, {}".format( event.city, event.country)) number = click.prompt(click.style("What is the number of the event in this city? " "If this is a second event, write 2. If third, then 3. You got it", bold=True, fg='yellow') ) date = gather_event_date_from_prompt() click.echo("The current team is: " + ", ".join( str(organizer) for organizer in event.team.all())) new_team = click.confirm(click.style( "Do you need to change the whole team?", bold=True, fg='yellow'), default=False ) return (event, number, date, new_team)
def command(): """Generate "Next events" section for the Dispatch.""" now = timezone.now() raw_dispatch_date = click.prompt(click.style( "What is the date of the previous Dispatch? (Format: YYYY-MM-DD)", bold=True, fg='yellow')) dispatch_date = (datetime.datetime .strptime(raw_dispatch_date, "%Y-%m-%d") .replace(tzinfo=datetime.timezone.utc)) # Get the events that happened since the last Dispatch. click.echo(click.style("PREVIOUS EVENTS", bold=True)) previous_events = Event.objects.filter( date__gt=dispatch_date.strftime("%Y-%m-%d"), date__lt=now.strftime("%Y-%m-%d")) result_previous = generate_html_content(previous_events) num_events = len(result_previous) if result_previous: click.echo( "%s event%s happened since the last dispatch: " % (apnumber(num_events), "s" if num_events > 1 else "") + ", ".join(result_previous) + ".") else: click.echo("No event took place since the last Dispatch.") # Get the events that were created since the last Dispatch. click.echo(click.style("NEXT EVENTS", bold=True)) next_events = Event.objects.all().filter( created_at__range=(dispatch_date, now)).order_by("date") sorted_event = groupby(next_events, key=lambda event: event.date.month) if next_events: for month, events in sorted_event: month_list = generate_html_content(events) click.echo(calendar.month_name[ month] + ": " + ", ".join(month_list) + "." + "<br />") else: click.echo( "There's no new event to announce. Don't forget to check our " "<a href='https://djangogirls.org/events/'>website</a> to get a " "list of our events planned for the next few months.") # Get the events with open registration. click.echo("OPEN REGISTRATION") open_events = Event.objects.all().filter( form__open_from__lte=now, form__open_until__gte=now) result_open = generate_html_content(open_events) if result_open: click.echo("Registrations are still open for: " + ", ".join(result_open) + ".") else: click.echo("There's no event with open registration.")
def get_team(team): """ We're asking user for names and address of the rest of the team, and append that to a list we got from get_main_organizer """ add_team = click.confirm(click.style( "Do you want to add additional team members?", bold=True, fg='yellow'), default=False) i = 1 while add_team: i += 1 name = click.prompt(click.style( "First and last name of #{0} member".format(i), bold=True, fg='yellow')) email = click.prompt(click.style( "E-mail address of #{0} member".format(i), bold=True, fg='yellow')) if len(name) > 0: try: team.append({'first_name': name.split(' ')[ 0], 'last_name': name.split(' ')[1], 'email': email}) except IndexError: team.append( {'first_name': name, 'last_name': '', 'email': email}) click.echo("All right, the #{0} team member of Django Girls is {1} ({2})".format( i, name, email)) add_team = click.confirm(click.style( "Do you want to add additional team members?", bold=True, fg='yellow'), default=False) return team
def command(): """Creates new Django Girls organizer""" event_id = click.prompt( click.style( "What's the event ID? NOT the event page ID. We want EVENT ID here", bold=True, fg='yellow')) event = Event.objects.get(id=event_id) click.echo("Ok, we're adding to an event in {}, {}".format( event.city, event.country)) team = [get_organizer_data()] while click.confirm( click.style("Do you want to add additional team members?", bold=True, fg='yellow'), default=False): team.append(get_organizer_data()) click.echo("OK! That's it. Now I'll add your organizers.") members = create_users(team, event) for member in members: click.echo("User {} has been added and notified".format(member.email)) click.echo(DELIMITER) click.echo("You still need to invite people to Google Group!")
def command(): """Creates new Django Girls organizer""" event_id = click.prompt(click.style( "What's the event ID? NOT the event page ID. We want EVENT ID here", bold=True, fg='yellow')) event = Event.objects.get(id=event_id) click.echo("Ok, we're adding to an event in {}, {}".format( event.city, event.country)) team = [get_organizer_data()] while click.confirm( click.style("Do you want to add additional team members?", bold=True, fg='yellow'), default=False): team.append(get_organizer_data()) click.echo("OK! That's it. Now I'll add your organizers.") members = create_users(team, event) for member in members: click.echo( "User {} has been added and notified".format(member.email)) click.echo(DELIMITER) click.echo("You still need to invite people to Google Group!")
def get_basic_info(): """ Here we're asking the user for: - city - country - date - url - event_email And return all these information. """ click.echo( "Hello there! Let's create new Django Girls event! So exciting!") click.echo("Let's start with some basics.") city = click.prompt( click.style("What is the name of the city?", bold=True, fg='yellow')) country = click.prompt( click.style("What is the name of the country?", bold=True, fg='yellow')) date = gather_event_date_from_prompt() url = click.prompt( click.style("What should be the URL of website? djangogirls.org/xxxx", bold=True, fg='yellow')) event_mail = click.prompt( click.style( "What is the mail adress of the event? [email protected]", bold=True, fg='yellow')) click.echo( "Ok, got that! Your new event will happen in {0}, {1} on {2}".format( city, country, date)) return (city, country, date, url, event_mail)
def gather_information(): click.echo("Hello there sunshine! We're gonna copy an event website now.") event = get_event( click.prompt( click.style( "First, give me the latest ID of the Event " "object you want to copy", bold=True, fg='yellow'))) while not event: event = get_event(click.prompt("Wrong ID! Try again")) click.echo("Ok, we're copying {}, {}".format(event.city, event.country)) number = click.prompt( click.style( "What is the number of the event in this city? " "If this is a second event, write 2. If third, then 3. You got it", bold=True, fg='yellow')) date = gather_event_date_from_prompt() click.echo("The current team is: " + ", ".join(str(organizer) for organizer in event.team.all())) new_team = click.confirm(click.style( "Do you need to change the whole team?", bold=True, fg='yellow'), default=False) return (event, number, date, new_team)
def get_organizer_data(): """ Returns a dictionary with first_name, last_name and email """ main_name = click.prompt( click.style("First and last name", bold=True, fg='yellow')) main_email = click.prompt( click.style("E-mail address", bold=True, fg='yellow')) data = {'name': main_name, 'email': main_email} return data
def get_main_organizer(): """ We're asking user for name and address of main organizer, and return a list of dictionary. """ team = [] click.echo("Now let's talk about the team. First the main organizer:") main_name = click.prompt(click.style("First and last name", bold=True, fg="yellow")) main_email = click.prompt(click.style("E-mail address", bold=True, fg="yellow")) team.append({"name": main_name, "email": main_email}) click.echo("All right, the main organizer is {0} ({1})".format(main_name, main_email)) return team
def get_organizer_data(): """ Returns a dictionary with first_name, last_name and email """ main_name = click.prompt(click.style( "First and last name", bold=True, fg='yellow')) main_email = click.prompt(click.style( "E-mail address", bold=True, fg='yellow')) data = { 'name': main_name, 'email': main_email } return data
def get_organizer_data(): """ Returns a dictionary with first_name, last_name and email """ main_name = click.prompt(click.style( "First and last name", bold=True, fg='yellow')) main_email = click.prompt(click.style( "E-mail address", bold=True, fg='yellow')) try: data = {'first_name': main_name.split(' ')[0], 'last_name': main_name.split(' ')[1], 'email': main_email} except IndexError: data = {'first_name': main_name, 'last_name': '', 'email': main_email} return data
def get_main_organizer(): """ We're asking user for name and address of main organizer, and return a list of dictionary. """ team = [] click.echo("Now let's talk about the team. First the main organizer:") main_name = click.prompt( click.style("First and last name", bold=True, fg='yellow')) main_email = click.prompt( click.style("E-mail address", bold=True, fg='yellow')) team.append({'name': main_name, 'email': main_email}) click.echo(u"All right, the main organizer is {0} ({1})".format( main_name, main_email)) return team
async def start_workers(self): all_groups = self.all_groups.copy() timer = Timer() timer.start() for name, _ in self.tasks: for group, sessions in all_groups.items(): click.echo( click.style( "→ Running task '{}' on group '{}' ({} workers).". format( name, group, len(sessions), ))) await self.start_group(name, group, sessions) if len(self.error_tasks[name]): click.echo( click.style( "✗ Task `{}` on Group '{}' failed.".format( name, group), fg='red', )) else: self.summary(name, group) click.echo( click.style( "✓ Task `{}` on Group '{}' done.".format( name, group), fg='green', )) click.echo(click.style("Task '{}' done.".format(name), fg='green')) self.done_task_count += 1 if self.done_task_count == len(self.tasks): timer.stop() click.echo( click.style( "All tasks done in {:.3f}s. Clients leaving.".format( timer.elapsed, self.worker_name, ), fg='red')) self.publish('worker.leave', options=self.publish_all)
def create_device(name, tracker_id): if not tracker_id or not name: return click.secho("Please provide a name and tracker id") device = Device(name=name, tracker_id=tracker_id) device.save() click.secho(f'Device {device.name} with tracker id: ' + click.style(device.tracker_id, bold=True, fg='green') + f' created successfully.\nNow you can add this device for a user with ' + f'given tracker id.')
def command(): """Creates new Django Girls organizer""" event_id = click.prompt( click.style( "What's the event ID? NOT the event page ID. We want EVENT ID here", bold=True, fg='yellow')) event = Event.objects.get(id=event_id) click.echo("Ok, we're adding to an event in {}, {}".format( event.city, event.country)) team = [get_organizer_data()] while click.confirm( click.style("Do you want to add additional team members?", bold=True, fg='yellow'), default=False): team.append(get_organizer_data()) click.echo("OK! That's it. Now I'll add your organizers.") members, members_as_list = create_users(team) for member in members: event.team.add(member) event.save() for member in members_as_list: if 'password' in member: click.echo("{} - email: {} password {}".format( member['first_name'], member['email'], member['password'])) else: click.echo( "{} - email: {} already has account".format( member['first_name'], member['email'])) click.echo(DELIMITER) invite_team_to_slack(members) click.echo(DELIMITER) click.echo("You still need to invite people to Google Group!")
def gather_event_date_from_prompt(): date = None while date is None: date_str = click.prompt( click.style("What is the date of the event? (Format: DD/MM/YYYY or MM/YYYY)", bold=True, fg="yellow") ) date = get_approximate_date(date_str) if date is None: click.secho("Wrong format! Try again :)", bold=True, fg="red") return date
def command(): """Creates new Django Girls organizer""" event_id = click.prompt(click.style( "What's the event ID? NOT the event page ID. We want EVENT ID here", bold=True, fg='yellow')) event = Event.objects.get(id=event_id) click.echo("Ok, we're adding to an event in {}, {}".format( event.city, event.country)) team = [get_organizer_data()] while click.confirm( click.style("Do you want to add additional team members?", bold=True, fg='yellow'), default=False): team.append(get_organizer_data()) click.echo("OK! That's it. Now I'll add your organizers.") members, members_as_list = create_users(team) for member in members: event.team.add(member) event.save() for member in members_as_list: if 'password' in member: click.echo("{} - email: {} password {}".format( member['first_name'], member['email'], member['password'])) else: click.echo( "{} - email: {} already has account".format( member['first_name'], member['email'])) click.echo(DELIMITER) invite_team_to_slack(members) click.echo(DELIMITER) click.echo("You still need to invite people to Google Group!")
def get_main_organizer(): """ We're asking user for name and address of main organizer, and return a list of dictionary. """ team = [] click.echo("Now let's talk about the team. First the main organizer:") main_name = click.prompt(click.style( "First and last name", bold=True, fg='yellow')) main_email = click.prompt(click.style( "E-mail address", bold=True, fg='yellow')) try: team.append({'first_name': main_name.split(' ')[ 0], 'last_name': main_name.split(' ')[1], 'email': main_email}) except IndexError: team.append({'first_name': main_name, 'last_name': '', 'email': main_email}) click.echo(u"All right, the main organizer is {0} ({1})".format( main_name, main_email)) return team
def gather_event_date_from_prompt(): date = None while date is None: date_str = click.prompt( click.style( "What is the date of the event? (Format: DD/MM/YYYY or MM/YYYY)", bold=True, fg='yellow')) date = get_approximate_date(date_str) if date is None: click.secho("Wrong format! Try again :)", bold=True, fg='red') return date
async def elect_leader(self, session): if self.leader is None: self.leader = session if self.leader == self.details.session: click.echo( click.style("Worker '{}' elected as leader".format( self.worker_name), fg='green')) self.subscriptions.append(await self.subscribe( self.receive_stat, 'leader.add_stat')) await self.build_roster() await self.start_workers()
def cas_importer(password, input_file): logger = logging.getLogger(__name__) logger.info("Reading CAS PDF") pdf_data = casparser.read_cas_pdf(input_file, password) period = pdf_data["statement_period"] email = pdf_data["investor_info"]["email"] click.echo("CAS file type " + click.style(pdf_data["file_type"], fg="green", bold=True)) click.echo("CAS statement period: " + click.style(period["from"], fg="green", bold=True) + " to " + click.style(period["to"], fg="green", bold=True)) click.echo("Email : " + click.style(email, fg="green", bold=True)) try: result = import_cas(pdf_data, 1) except ValueError as e: click.style("Error while importing CAS :: %s" % str(e), bold=True, fg="red") else: click.echo("Total Transactions : " + click.style( f"{result['transactions']['total']}", fg="green", bold=True)) click.echo("Imported : " + click.style( f"{result['transactions']['total']}", fg="green", bold=True))
def command(): """Duplicates Django Girls event with a new date""" # Gather data (event, number, date, new_team) = gather_information() organizers = event.team.all() # Remove #{no} from name: name = event.name.split('#')[0].strip() number = int(number) # Change the name of previous event to {name} #{number-1} event.name = "{} #{}".format(name, number-1) event.save() # Copy event with a name {name} #{number}, new date and empty stats new_event = Event.objects.get(id=event.id) new_event.pk = None new_event.name = "{} #{}".format(name, number) new_event.page_title = "{} #{}".format(name, number) new_event.date = date new_event.is_page_live = False new_event.attendees_count = None new_event.applicants_count = None new_event.save() # Edit team and previous email or keep them if new_team: # Create a new team with a new main organizer main_organizer = get_main_organizer() team = get_team(main_organizer) members = create_users(team, new_event) new_event.main_organizer = members[0] # Edit previous email account event.email = "{}{:02d}{}@djangogirls.org".format(event.email.split('@')[0], event.date.month, event.date.year) else: new_event.team = organizers # Change the title and url of previous event page event.page_title = "{} #{}".format(name, number-1) event.page_url = "{}{}".format(event.page_url, number-1) event.save() # Copy all EventPageContent objects for obj in event.content.all(): new_content = obj new_content.id = None new_content.event = new_event new_content.save() new_content.coaches = obj.coaches.all() new_content.sponsors = obj.sponsors.all() # Copy all EventPageMenu objects for obj in event.menu.all(): new_obj = obj new_obj.pk = None new_obj.event = new_event new_obj.save() # Brag on Slack brag_on_slack_bang(new_event.city, new_event.country, new_event.team.all()) click.echo(click.style("Website is ready here: https://djangogirls.org/{0}".format(new_event.page_url), bold=True, fg="green")) click.echo("Congrats on yet another event!")
def summary(self, task, group): stats = self.stats[task][group] for stat in stats.values(): click.echo(click.style('ℹ {!s}'.format(stat), fg='blue'))
def echo(text, value): click.echo(click.style(text, fg='green') + '{0}'.format(value))
def echo(text, value): click.echo(click.style(text, fg="green") + "{0}".format(value))
def command(): """Duplicates Django Girls event with a new date""" # Gather data (event, number, date, new_team) = gather_information() organizers = event.team.all() # Remove #{no} from name: name = event.name.split('#')[0].strip() number = int(number) # Change the name of previous event to {name} #{number-1} event.name = "{} #{}".format(name, number - 1) event.save() # Copy event with a name {name} #{number}, new date and empty stats new_event = Event.objects.get(id=event.id) new_event.pk = None new_event.name = "{} #{}".format(name, number) new_event.page_title = "{} #{}".format(name, number) new_event.date = date new_event.is_page_live = False new_event.attendees_count = None new_event.applicants_count = None new_event.save() # Edit team and previous email or keep them if new_team: # Create a new team with a new main organizer main_organizer = get_main_organizer() team = get_team(main_organizer) members = create_users(team, new_event) new_event.main_organizer = members[0] # Edit previous email account event.email = "{}{:02d}{}@ng-boat.pl".format( event.email.split('@')[0], event.date.month, event.date.year) else: new_event.team.set(organizers) # Change the title and url of previous event page event.page_title = "{} #{}".format(name, number - 1) event.page_url = "{}{}".format(event.page_url, number - 1) event.save() # Copy all EventPageContent objects for obj in event.content.all(): new_content = obj new_content.id = None new_content.event = new_event new_content.save() new_content.coaches = obj.coaches.all() new_content.sponsors = obj.sponsors.all() # Copy all EventPageMenu objects for obj in event.menu.all(): new_obj = obj new_obj.pk = None new_obj.event = new_event new_obj.save() # Brag on Slack brag_on_slack_bang(new_event.city, new_event.country, new_event.team.all()) click.echo( click.style("Website is ready here: https://ng-boat.pl/{0}".format( new_event.page_url), bold=True, fg="green")) click.echo("Congrats on yet another event!")
def command(url, email, password, game): """ Verify SIMPL API deployment is in good working order. """ ANY_FAILURES = False click.echo(click.style("=== Verifying SIMPL API at: ", fg='green') + url) # Check DNS try: click.secho("- Checking DNS... ", fg='green', nl=False) check_dns(url) click.secho('OK', fg='green') except Exception: ANY_FAILURES = True click.secho('FAILED', fg='red') # Check HTTPS try: click.secho("- Checking HTTP/HTTPS Connectivity... ", fg='green', nl=False) check_http_connection(url) click.secho('OK', fg='green') except Exception: ANY_FAILURES = True click.secho('FAILED', fg='red') # Check admin and API if we're supposed to click.secho("- Checking admin login... ", fg='green', nl=False) try: check_admin_login(url, email, password) click.secho('OK', fg='green') except Exception: ANY_FAILURES = True click.secho('FAILED', fg='red') # Check API endpoint try: click.secho("- Checking API endpoints... ", fg='green', nl=False) check_game_api(url, email, password) click.secho('OK', fg='green') except Exception: ANY_FAILURES = True click.secho('FAILED', fg='red') # Check API for Game try: click.secho("- Checking for game '{}' in API... ".format(game), fg='green', nl=False) check_for_game_in_api(url, game, email, password) click.secho('OK', fg='green') except Exception: ANY_FAILURES = True click.secho('FAILED', fg='red') # Exit with a non-zero exit code on any failures if ANY_FAILURES: click.secho("=== NOT OK ===", fg='red') sys.exit(1) else: click.secho("=== ALL OK YAY! ===", fg='green')