Пример #1
0
 def __init__(self):
     print bcolors.WARNING + 'Loading 2016 Election Campaign Manager...' + bcolors.ENDC
     self.client = BaseClient()
     self.submissions_list = self.client.get_submissions_list()
     self.voters = self.generate_voter_instances(self.submissions_list)
     self.politicians = self.generate_politician_instances()
     self.votes_democrat = []
     self.votes_republican = []
Пример #2
0
    def __init__(self):
        BaseClient.__init__(
                self, 'Guild Client')

        self.top_gg = DBLClient(
                self,
                getenv('TOKEN_TOP_GG'),
                webhook_path='/dblwebhook',
                webhook_auth='password',
                webhook_port=5000)

        self.bots_on_discord = BotsOnDiscordHandler(
                self, getenv('TOKEN_BOTS_ON_DISCORD'))

        self.discord_bots = DiscordBotsHandler(
                self, getenv('TOKEN_DISCORD_BOTS'))
Пример #3
0
    def __init__(self, name, conf, os_auth_info):
        BaseClient.__init__(self, name, conf, os_auth_info)
        self.handle = client.Client(
                           os_auth_info["username"],
                           os_auth_info["password"],
                           os_auth_info["tenant_name"],
                           os_auth_info["auth_url"],
                           insecure=True,
                           service_type="compute")

        # Maybe the client doesn't prefer ssh route
        self.ssh_info = conf.get("ssh", None)

        servers = []
        try:
            servers.extend(self.handle.servers.list())
        except NotFound:
            logging.warn("No servers present for client %s" % name)

        self.pattern = re.compile("^" + os_auth_info["username"] + "-[0-9]{3}")
        for inst in servers:
            if not self.pattern.match(inst.name):
                continue
            instance = Instance(inst, self.ssh_info)
            instanceId = instance.get_id()

            self.id2inst[instanceId] = instance

            vols = []
            try:
                vols.extend(self.handle.volumes.get_server_volumes(instanceId))
            except NotFound:
                logging.warn("No volume attached for instance %s(%s)" % (instance.get_name(), instance.get_id()))

            volumes = self.id2vols[instanceId] = []
            for vol in vols:
                volumes.append(Volume(instance, vol))
Пример #4
0
 def __init__(self):
     BaseClient.__init__(self, url_prefix=RODIMUS_SERVICE_URL, version=RODIMUS_SERVICE_VERSION)
Пример #5
0
import unittest
import sys
from os import path
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
from base_client import BaseClient
import requests
import httpretty

client = BaseClient()
mock_submissions_json = {
    'total':
    '2',
    'submissions': [
        {
            'remote_addr': '50.115.104.50',
            'read': '1',
            'timestamp': '2015-10-09 17:17:31',
            'longitude': '-80.193702697754',
            'user_agent':
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
            'payment_status': '',
            'latitude': '25.774299621582',
            'id': '218459301'
        },
    ],
    'pages':
    1
}
mock_submission_ids = ['218459301']
mock_submission = [{
    'field': '36379032',
Пример #6
0
 def __init__(self):
     BaseClient.__init__(self, url_prefix=TELETRAAN_SERVICE_URL, version=TELETRAAN_SERVICE_VERSION)
Пример #7
0
class Campaign(object):
    VALID_VIEWS = ['Socialist', 'Neutral', 'Conservative', 'Tea Party', 'Liberal']
    def __init__(self):
        print bcolors.WARNING + 'Loading 2016 Election Campaign Manager...' + bcolors.ENDC
        self.client = BaseClient()
        self.submissions_list = self.client.get_submissions_list()
        self.voters = self.generate_voter_instances(self.submissions_list)
        self.politicians = self.generate_politician_instances()
        self.votes_democrat = []
        self.votes_republican = []

    def list_submitted_surveys(self):
        for index, voter in enumerate(self.voters):
            print '%s - %s %s - %s - Voter ID: %s' % (index, voter.first_name, voter.last_name, voter.views, voter.submission_id)

    def generate_voter_instances(self, submissions):
        all_voters = []
        for submission in submissions:
            voter_data = self.client.get_submission_details(submission)
            voter = Voter(voter_data['first_name'], voter_data['last_name'], voter_data['views'], voter_data['submission_id'])
            all_voters.append(voter)
        return all_voters

    def generate_politician_instances(self):
        politicians = []
        democrat = Politician('Hilary', 'Clinton', 'Democrat')
        politicians.append(democrat)
        republican = Politician('Jeb', 'Bush', 'Republican')
        politicians.append(republican)
        return politicians

    def submit_vote(self, first_name, last_name, views):
        response = self.client.send_submission(first_name, last_name, views)
        return response

    def create_voter(self):
        print 'Alright, let\'s create a voter'
        first_name = raw_input('What is the voter\'s first name?').lower().capitalize()
        last_name = raw_input('Ok, what is the voter\'s last name?').lower().capitalize()
        print 'For this survey, please select one of the following views:'
        for view in self.VALID_VIEWS:
            print view
        views = raw_input().lower().capitalize()
        voter = Voter(first_name, last_name, views)
        response = self.submit_vote(first_name, last_name, views)
        if response == 200:
            print 'Submitting your survey. Please wait...'
            self.submissions_list = self.client.get_submissions_list()
            self.voters = self.generate_voter_instances(self.submissions_list)
            print 'Survey was submitted successfully'
        else:
            print 'There was an error submitting your survey, please try again later.'
        return

    def update_voter_views(self):
        print 'Please indicate the ID (it\'s the value of the first column) of the voter whose views you\'d like to update:'
        self.list_submitted_surveys()
        voter_id = raw_input('\n-->')
        submission_id = self.voters[int(voter_id)].submission_id
        print 'Alright, now select the new views for this voter.'
        for view in self.VALID_VIEWS:
            print view
        views = raw_input('\n-->').lower().capitalize()
        response = self.client.update_submission(submission_id, views)
        if response == 200:
            self.voters[int(voter_id)].views = views
            print 'Voter views updated successfully.'
        else:
            print 'There was an error while submitting your request, please try again later.'

    def vote(self):
        for politician in self.politicians:
            for voter in self.voters:
                rnd = random.random()
                voter.decide_vote(politician, rnd)

        self.tally()

    def tally(self):
        votes_democrat = 0
        votes_republican = 0
        votes_null = 0
        for voter in self.voters:
            if voter.vote == 'Democrat':
                votes_democrat += 1
            elif voter.vote == 'Republican':
                votes_republican += 1
            else:
                votes_null += 1

        print '\n'
        print 'Based on our estimations derived from this survey, the 2016 Election would go to:'
        if votes_democrat > votes_republican:
            print bcolors.OKBLUE
            self.politicians[0].list_politician()
            print bcolors.ENDC
        elif votes_republican > votes_democrat:
            print bcolors.FAIL
            self.politicians[1].list_politician()
            print bcolors.ENDC
        else:
            print 'It is impossible for us to derive a potential winner based on the amount of surveys collected at this time.'

        total_votes = votes_democrat + votes_republican + votes_null
        pct_democrat = votes_democrat / total_votes * 100
        pct_republican = votes_republican / total_votes * 100
        pct_null = votes_null / total_votes * 100

        print 'The statistics breakdown is as follows:'
        print bcolors.OKBLUE + '%0.2f percent voted democrat' % pct_democrat
        print bcolors.FAIL + '%0.2f percent voted republican' % pct_republican
        print bcolors.WARNING + '%0.2f percent abstained from voting' % pct_null
        print bcolors.ENDC

    def start_simulation(self):
        print '\nWelcome to the' + bcolors.FAIL + ' 2016' + bcolors.OKBLUE + ' Election ' + bcolors.FAIL + ' Campaign Manager \n'
        print bcolors.ENDC + 'The campagin manager lets you submit surveys on behalf of voters, ' + \
               'update information submitted by users, and run simulations to see the most likely candidate to' + \
               'become the President of the United States in 2016.'
        print 'Please select onf the following options:'
        while True:
            print bcolors.WARNING + '[LIST VOTERS] [LIST CANDIDATES] [SUBMIT VOTE] [UPDATE SUBMISSION] [RUN SIMULATION] [EXIT]' + bcolors.ENDC
            response = raw_input().upper()
            if response == 'SUBMIT VOTE':
                self.create_voter()
            elif response == 'LIST VOTERS':
                self.list_submitted_surveys()
            elif response == 'LIST CANDIDATES':
                for politician in self.politicians:
                    politician.list_politician()
            elif response == 'UPDATE SUBMISSION':
                self.update_voter_views()
            elif response == 'RUN SIMULATION':
                self.vote()
            elif response == 'EXIT':
                print 'Thank you for using the 2016 Campagin Manager'
                exit()
            else:
                print 'Please select a valid command'
Пример #8
0
    def __init__(self):
        BaseClient.__init__(self, 'Message Client')

        self.mention = None
Пример #9
0
 def __init__(self):
     BaseClient.__init__(self,
                         url_prefix=RODIMUS_SERVICE_URL,
                         version=RODIMUS_SERVICE_VERSION)
Пример #10
0
 def __init__(self):
     BaseClient.__init__(self,
                         url_prefix=TELETRAAN_SERVICE_URL,
                         version=TELETRAAN_SERVICE_VERSION)