Beispiel #1
0
def process_musicbed(vargs):
    """
    Main MusicBed path.
    """

    # let's validate given MusicBed url
    validated = False
    if vargs['artist_url'].startswith( 'https://www.musicbed.com/' ):
        splitted = vargs['artist_url'][len('https://www.musicbed.com/'):].split( '/' )
        if len( splitted ) == 3:
            if ( splitted[0] == 'artists' or splitted[0] == 'albums' or splitted[0] == 'songs' ) and splitted[2].isdigit():
                validated = True

    if not validated:
        puts( colored.red( 'process_musicbed: you provided incorrect MusicBed url. Aborting.' ) )
        puts( colored.white( 'Please make sure that url is either artist-url, album-url or song-url.' ) )
        puts( colored.white( 'Example of correct artist-url: https://www.musicbed.com/artists/lights-motion/5188' ) )
        puts( colored.white( 'Example of correct album-url:  https://www.musicbed.com/albums/be-still/2828' ) )
        puts( colored.white( 'Example of correct song-url:   https://www.musicbed.com/songs/be-still/24540' ) )
        return

    filenames = scrape_musicbed_url(vargs['artist_url'], vargs['login'], vargs['password'], num_tracks=vargs['num_tracks'], folders=vargs['folders'], custom_path=vargs['path'])

    if vargs['open']:
        open_files(filenames)
Beispiel #2
0
    def execute(self):
        """Execute the story command.
        """
        puts(self.story.name)
        puts()

        if self.story.estimate is None:
            puts(self.story.type.capitalize())
        elif self.story.estimate >= 0:
            puts("{0} Estimate: {1:d} points".format(
                self.story.type.capitalize(), self.story.estimate))
        else:
            puts("{0} Unestimated.".format(self.story.type.capitalize()))

        if self.story.description:
            puts()
            puts(colored.cyan(self.story.description))

        puts()
        puts(colored.white("Requested by {0} on {1}".format(
            self.story.requester,
            self.story.created.strftime("%d %b %Y, %I:%M%p"))))
        puts(colored.white(self.story.url))

        if self.namespace.comments:
            comments = self.pt.get_comments(self.project, self.story)

            for comment in comments:
                puts()
                puts(colored.yellow("{0} ({1})".format(comment.author,
                    comment.created)))
                puts()
                puts(comment.text)
Beispiel #3
0
def download_track(track, album_name=u'', keep_previews=False, folders=False, filenames=[], custom_path=''):
    """
    Given a track, force scrape it.
    """

    hard_track_url = get_hard_track_url(track['id'])

    # We have no info on this track whatsoever.
    if not 'title' in track:
        return None

    if not keep_previews:
        if (track.get('duration', 0) < track.get('full_duration', 0)):
            puts_safe(colored.yellow("Skipping preview track") + colored.white(": " + track['title']))
            return None

    # May not have a "full name"
    name = track['user'].get('full_name', '')
    if name == '':
        name = track['user']['username']

    filename = sanitize_filename(name + ' - ' + track['title'] + '.mp3')

    if folders:
        name_path = join(custom_path, name)
        if not exists(name_path):
            mkdir(name_path)
        filename = join(name_path, filename)
    else:
        filename = join(custom_path, filename)

    if exists(filename):
        puts_safe(colored.yellow("Track already downloaded: ") + colored.white(track['title']))
        return None

    # Skip already downloaded track.
    if filename in filenames:
        return None

    if hard_track_url:
        puts_safe(colored.green("Scraping") + colored.white(": " + track['title']))
    else:
        # Region coded?
        puts_safe(colored.yellow("Unable to download") + colored.white(": " + track['title']))
        return None

    filename = download_file(hard_track_url, filename)
    tagged = tag_file(filename,
             artist=name,
             title=track['title'],
             year=track['created_at'][:4],
             genre=track['genre'],
             album=album_name,
             artwork_url=track['artwork_url'])
    if not tagged:
        wav_filename = filename[:-3] + 'wav'
        os.rename(filename, wav_filename)
        filename = wav_filename

    return filename
Beispiel #4
0
    def run(self):
        #SELECT * FROM users
        all_users = User.objects.all()
        #users_vec = []
        #for user in all_users:
        #    users_vec.append(user.id)

        session_counter = 0
        print colored.white("Generating Friendships:")
        for user in progress.bar(all_users):
            num_friends = Cumulative_vec_distr(friends_x_user)
            what_friends = random.sample(all_users, num_friends)

            for i in xrange(len(what_friends)):
                # create friendship relation friend
                friend = UserFollower(
                    owner=user,
                    follower=what_friends[i],
                    context=random.randint(1,5)
                )
                
                friend.save()
                session_counter += 1

                if session_counter > 5000:
                    session_counter = 0
                    transaction.commit()

        transaction.commit()
Beispiel #5
0
    def run(self):
        """ 80% pending vote, 17% up vote, y 3% down vote """
        
        # SELECT circuit.id FROM circuits
        all_circuits = Circuit.objects.all()

        session_counter = 0
        print colored.white("Inserting ratings for circuit:")
        for ct in progress.bar(all_circuits):
            
            ct_visitors = ct.get_visitors()
            for visitor in ct_visitors:
                prob_vote = random.randint(0,100)
                
                if prob_vote <= 80:
                    continue
                elif prob_vote > 80 and prob_vote <= 93:
                    voto = 1
                else:
                    voto = -1

                ct_r = CircuitRating(user=visitor,
                    circuit=ct,
                    vote = voto
                )   

                ct_r.save()
                session_counter += 1
                if session_counter >= 5000:
                    session_counter = 0
                    transaction.commit()

        transaction.commit()
Beispiel #6
0
    def execute(self):
        """Execute this issue command.
        """
        puts(self.issue.title)

        if self.issue.milestone:
            puts()
            puts("Milestone: {0}".format(self.issue.milestone))

        if self.issue.description:
            puts()
            puts(colored.cyan(self.issue.description))

        puts()
        puts(colored.white("Created by {0} on {1}".format(
            self.issue.user.login,
            self.issue.created.strftime("%d %b %Y, %I:%M%p"))))
        puts(colored.white(self.issue.url))

        if self.namespace.comments:
            for comment in self.github.get_comments(self.issue):
                puts()
                puts(colored.yellow("{0} ({1})".format(
                    comment.user.login, comment.created)))
                puts()
                puts(str(comment))
Beispiel #7
0
    def make_graph (self, outputfile):
        g = Graph()

        for k, v in self.__prefixes.iteritems():
            g.bind(k, v)

        if self.verbose: puts(colored.green("Establishing URIRefs for Provenances..."))
        for k, v in self.dict_provenances.iteritems():
            v.establish_URIRef()

        if self.verbose: puts(colored.green("Putting Provenances to Graph..."))
        for k, v in self.dict_provenances.iteritems():
            v.put_on_graph(g)

        if self.verbose: puts(colored.green("Putting Chronicles to Graph..."))
        for k, v in self.dict_chronicles.iteritems():
            v.put_on_graph(g)

        if self.verbose: puts(colored.green("Serialising Graph..."))

        g.serialize(outputfile, format="turtle")

        if self.verbose:
            puts(colored.white("+-------------------+"))
            puts(colored.white("| ")+colored.blue("cxxr2prov Summary")+colored.white(" |"))
            puts(colored.white("+-------------------+"))
            puts("Number of PROV Entities: " + str(len(self.dict_provenances)))
            puts("Number of PROV Activities: " + str(len(self.dict_chronicles)))
            puts("Number of PROV used attributes: " + str(self.count_used))
            puts("Number of PROV wasGeneratedBy attributes: " + str(self.count_was_generated_by))
Beispiel #8
0
    def run(self, new_users=None):

        if new_users == None:
            #SELECT screen_name, (free_time_score + explorer_score)/4
            #FROM users
            #ORDER BY (free_time_score + explorer_score) DESC LIMIT 1000;
            all_users = SimUser.objects.order_by('-explorer_score')[:1000]
        else:
            #all_users = self.session.query(User).order_by((User.id).desc()).limit(new_users).all()
            pass

        session_counter = 0
        print colored.white("Generating follows:")
        for usuario in progress.bar(all_users):

            #SELECT DISTINCT(tc.topic_id)
            #FROM visits as v, topic_circuit as tc 
            #WHERE v.circuit_id = tc.circuit_id and v.user_id = all_users.id;
            vis = usuario.user.visits.values('circuit')
            user_visited_cts_ids = []
            for elem in vis:
                user_visited_cts_ids.append(elem['circuit'])

            all_user_topics = []
            for ct in user_visited_cts_ids:
                cir = Circuit.objects.get(id=ct)
                all_user_topics = cir.topics.values('id')
            
            all_user_tpc_ids = []
            for tp in all_user_topics:
                all_user_tpc_ids.append(tp['id'])
            
            # Obtaining how many follows the user will do
            num_follows = (usuario.free_time_score + usuario.explorer_score)/4
            
            while num_follows > len(all_user_topics):
                num_follows -= 1

            # User will follow this topics     
            topics_to_follow = random.sample(all_user_tpc_ids, num_follows)

            for fw in xrange(num_follows):
                # Get the topic from DB
                the_topic = Topic.objects.get(id=topics_to_follow[fw])
                # Create the object Follow
                follow = TopicFollow(date = self.date,
                    user = usuario.user,
                    topic = the_topic
                )

                # Save to DB
                follow.save()
                session_counter += 1

                if session_counter >= 5000:            
                    transaction.commit() 
                    session_counter = 0

        transaction.commit()
Beispiel #9
0
def auto_upload():
    apple_plist = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" """ + \
""" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.cwoebker.como-update</string>
    <key>OnDemand</key>
    <true/>
    <key>RunAtLoad</key>
    <false/>
    <key>ProgramArguments</key>
    <array>
        <string>%s</string>
        <string>upload</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
      <key>Hour</key>
      <integer>11</integer>
      <key>Minute</key>
      <integer>0</integer>
    </dict>
</dict>
</plist>"""
    if is_osx:
        plist_path = os.path.expanduser(
            "~/Library/LaunchAgents/com.cwoebker.como-update.plist")
        if os.path.exists(plist_path):
            os.system("launchctl unload %s" % plist_path)
            os.remove(plist_path)
            puts(colored.white("como will not upload data"))
        else:
            with open(plist_path, "w") as plist_file:
                plist_file.write(
                    apple_plist % os.popen('which como').read().rstrip('\n'))
            os.system("launchctl load %s" % plist_path)
            puts(colored.white("como will automatically upload the data"))
    elif is_lin:
        user_cron = CronTab()
        user_cron.read()
        if len(user_cron.find_command("como-update")) > 0:
            user_cron.remove_all("como-update")
            user_cron.write()
            puts(colored.white("como will not upload data"))
        else:
            job = user_cron.new(command="como-update")
            job.minute.every(2)
            #job.minute.on(0)
            #job.hour.on(19)
            user_cron.write()
            puts(colored.white("como will automatically upload the data"))
    elif is_win:
        error("Sorry there is no auto-upload for windows.")
Beispiel #10
0
    def apply(self, context, project):
        """
        Check if this file needs to get uploaded or not. In order to do so,
        we could rely on ETAG for normal files, but one of the mainline
        cases of gordon is to upload .zip files, and identical source folders
        don't have consistent hashes when you zip them, so we need to
        workaround this by generating our own hash by reading the zip content
        in a particular order."""

        self.project = project
        self.context = context
        self.bucket = self._get('bucket', self.context)
        self.key = self._get('key', self.context)

        self.filename = self._friendly_name = os.path.join(
            project.build_path,
            self._get('filename', context)
        )

        self.filename = self.prepare_file(self.filename)

        s3client = boto3.client('s3')
        try:
            obj = s3client.head_object(Bucket=self.bucket, Key=self.key)
        except Exception:
            obj = None

        # Calculate the hash of this file
        file_hash = utils.get_file_hash(self.filename)

        # If the object is present, and the hash in the metadata is the same
        # we don't need to upload it.
        if obj and file_hash == obj['Metadata'].get('sha1'):
            self._success(file_hash, project.puts)
            if self.project.debug:
                project.puts(colored.white(u"✸ File with hash {} already present in {}/{}.".format(
                    file_hash[:8], self.bucket, self.key))
                )
            return self.output(obj['VersionId'])

        # If the key is not present or the hash doesn't match, we need to upload it.
        if self.project.debug:
            project.puts(colored.white(u"✸ Uploading file with hash {} to {}/{}.".format(
                file_hash[:8], self.bucket, self.key))
            )

        obj = boto3.resource('s3').Object(self.bucket, self.key)
        obj.upload_file(self.filename, ExtraArgs={'Metadata': {'sha1': file_hash}})
        self._success(file_hash, project.puts)
        return self.output(obj.version_id)
Beispiel #11
0
    def show(self, detailed=False):

        d = self.request()

        # Imprime a tradução
        print("{0}: {1}".format(colored.white(self.PARAMS["tl"]), colored.red(d["trans"])))

        # Caso solicitado, imprime mais informações
        if detailed:
            print("{0}: {1}".format(colored.white(self.PARAMS["sl"]), d["orig"]))
            print()
            for _class in d["classes"]:
                print("{0}: {1}".format(colored.white(_class["name"]), ", ".join([word for word in _class["terms"]])))

        print()
Beispiel #12
0
    def delete(self):

        if self.dry_run:
            self.puts(
                colored.yellow(
                    ("\nYou are trying to delete this project's resources!\n"
                     "By default this command runs in dry-run mode. If you are ok \n"
                     "with the following resources being deleted, you can run this\n"
                     "command with --confirm to do the actual deletion.\n"
                     "\nNOTHING IS GOING TO BE DELETED!\n")
                )
            )
            self.puts(colored.blue("The following resources would be deleted..."))
        else:
            self.puts(colored.blue("Deleting project resources..."))

        context = self.get_initial_context()

        with indent(2):
            self.puts(colored.magenta("\nRegion:{Region}\nStage: {Stage}\n".format(**context)))

        for (number, name, filename, template_type) in self.steps():
            with indent(2):
                self.puts(colored.cyan("{} ({})".format(filename, template_type)))
            with indent(4):
                if self.debug:
                    self.puts(colored.white(u"✸ Delete template {} with context {}".format(filename, context)))
                getattr(self, 'delete_{}_template'.format(template_type))(name, filename, context)
Beispiel #13
0
 def downloadPodcastFile(self, url, title, description='', current=0, total=0, thumb=""):
     podcast = PrDlPodcast(url, title, description='', track_number=current, thumbnail_url=thumb)
     puts(colored.blue('[' + str(current) + '/' + str(total) + ']'))
     puts(colored.white('Tytuł: ' + title, bold=True))
     puts(colored.white('Link: ' + url))
     puts(colored.white('Plik: ' + podcast.file_name))
     if thumb != "":
         puts(colored.white('Miniaturka: ' + thumb))
     if (os.path.isfile(podcast.file_name)):
         print '[!] Plik o tej nazwie istnieje w katalogu docelowym'
     else:
         if (self.confirmSave(self.save_all) == 1):
             download(url, './' + podcast.file_name)
             podcast.id3tag()
             podcast.downloadThumbnail()
             podcast.addThumbnail()
Beispiel #14
0
 def download_jfsfile(remote_object, tofolder=None, checksum=False):
     'Helper function to get a jfsfile and store it in a local folder, optionally checksumming it. Returns boolean'
     if tofolder is None:
         tofolder = '.' # with no arguments, store in current dir
     total_size = remote_object.size
     if remote_object.state in (JFS.ProtoFile.STATE_CORRUPT, JFS.ProtoFile.STATE_INCOMPLETE):
         puts(colored.red('%s was NOT downloaded successfully - Incomplete file' % remote_file.name))
         return False
     topath = os.path.join(tofolder, remote_object.name)
     with open(topath, 'wb') as fh:
         bytes_read = 0
         puts(colored.white('Downloading: %s, size: %s \t' % (remote_object.name, 
                                                              print_size(total_size, humanize=True))))   
         with ProgressBar(expected_size=total_size) as bar:
             for chunk_num, chunk in enumerate(remote_object.stream()):
                 fh.write(chunk)
                 bytes_read += len(chunk)
                 bar.show(bytes_read)
     if checksum:
         md5_lf = JFS.calculate_md5(open(topath, 'rb'))
         md5_jf = remote_object.md5
         logging.info('%s - Checksum for downloaded file' % md5_lf)
         logging.info('%s - Checksum for server file' % md5_jf)
         if md5_lf != md5_jf:
             puts(colored.blue('%s - Checksum for downloaded file' % md5_lf))
             puts(colored.blue('%s - Checksum for server file' % md5_jf))
             puts(colored.red('%s was NOT downloaded successfully - cheksum mismatch' % remote_object.name))
             return False
         puts(colored.green('%s was downloaded successfully - checksum  matched' % remote_object.name))
     return True
Beispiel #15
0
def scrape_mixcloud_url(mc_url, num_tracks=sys.maxsize, folders=False, redownload=False):
    """

    Returns filenames to open.

    """

    try:
        data = get_mixcloud_data(mc_url)
    except Exception as e:
        puts(colored.red("Problem downloading ") + mc_url)
        print(e)
        return []

    filenames = []

    track_artist = sanitize_filename(data["artist"])
    track_title = sanitize_filename(data["title"])
    track_fullfilepath = get_path(
        folders, track_artist, track_title, album_name=None, track_number=None, file_ext=data["mp3_url"][-3:]
    )

    download_text = colored.green("Downloading")
    if exists(track_fullfilepath):
        if redownload:
            download_text = colored.yellow("Redownloading")
        else:
            puts(colored.yellow("Track already downloaded: ") + colored.white(data["title"]))
            return []

    puts(
        download_text
        + colored.white(": " + data["artist"] + " - " + data["title"] + " (" + track_fullfilepath[-4:] + ")")
    )
    download_file(data["mp3_url"], track_fullfilepath)
    if track_fullfilepath[-4:] == ".mp3":
        tag_file(
            track_fullfilepath,
            artist=data["artist"],
            title=data["title"],
            year=data["year"],
            genre="Mix",
            artwork_url=data["artwork_url"],
        )
    filenames.append(track_fullfilepath)

    return filenames
Beispiel #16
0
def rectxt():
    numb = random.randint(0,30)
    numb = str(numb)
    #categ  = input('Which number: ')
    r2 = requests.get('http://api.trademe.co.nz/v1/Search/General.json?category=' + numb + '&sort_order=BidsMost')
    r3 = requests.get('http://api.trademe.co.nz/v1/Listings/Latest.json')
    j2 = json.loads(r2.text)
    j3 = json.loads(r3.text)
    #pprint(j2)  #here's the final respone, printed out nice an readable format
    #ed2 = str(j2)
    x = j3[u'List']
    #pprint(x)
    for info in x:
         ContentPath = info[u'CategoryPath']      
         ContentPath = str(ContentPath)
        
         ContentRegion = info[u'Region']
         ContentRegion = str(ContentRegion)
         
         ContentTitle = info[u'Title']
         ContentTitle = str(ContentTitle)
         
         ContentBuyNow = info[u'PriceDisplay']
         ContentBuyNow = str(ContentBuyNow)
         
         ContentSuburb = info[u'Suburb']
         ContentSuburb = str(ContentSuburb)
         #ContentImage = info[u'PictureHref']
         #ContentImage = str(ContentImage)
         #pprint(ContentTitle)
         puts(colored.red(ContentTitle))
         #pprint(ContentPath)
         puts(colored.white(ContentPath))
         #pprint(ContentRegion)
         puts(colored.green(ContentRegion))
         pprint(ContentBuyNow)
         files = open('doc', 'w')
         title = open('title', 'w')
         #imagePic = open('imagePic', 'w')
         #imagePic.write(ContentImage)
         #imagePic.close()
         title.write(ContentTitle)
         title.close()
         files.write('<h1> <p>')
         files.write(ContentTitle)
         files.write('</h1></p><h2><p>')
         files.write('Buy now: ') 
         files.write(ContentBuyNow)
         files.write('</p>')
         files.write('Area: ')
         files.write(ContentRegion)
         files.write(', ')
         files.write(ContentSuburb)
         files.write('</h2>')
         #files.write('<img class=\"aligncenter\" alt=\"\" src =\"')
         #files.write(ContentImage)
         #files.write('\" width=\"300\" height=\"150\" />')
         files.close()
Beispiel #17
0
def scrape_mixcloud_url(mc_url, num_tracks=sys.maxsize, folders=False):
    """

    Returns filenames to open.

    """

    try:
        data = get_mixcloud_data(mc_url)
    except Exception as e:
        puts(colored.red("Problem downloading ") + mc_url)
        print(e)
        return []

    filenames = []

    track_artist = sanitize_filename(data["artist"])
    track_title = sanitize_filename(data["title"])
    track_filename = track_artist + " - " + track_title + data["mp3_url"][-4:]

    if folders:
        if not exists(track_artist):
            mkdir(track_artist)
        track_filename = join(track_artist, track_filename)
        if exists(track_filename):
            puts(colored.yellow("Skipping") + colored.white(": " + data["title"] + " - it already exists!"))
            return []

    puts(
        colored.green("Downloading")
        + colored.white(": " + data["artist"] + " - " + data["title"] + " (" + track_filename[-4:] + ")")
    )
    download_file(data["mp3_url"], track_filename)
    if track_filename[-4:] == ".mp3":
        tag_file(
            track_filename,
            artist=data["artist"],
            title=data["title"],
            year=data["year"],
            genre="Mix",
            artwork_url=data["artwork_url"],
        )
    filenames.append(track_filename)

    return filenames
Beispiel #18
0
 def removelinks(self, links=None, verbose=False):
     """ CMD: Remove a link on Database """
     links = self._links_validator(links)
     is_removed = False
     for l in links:
         if not self.db.link_exist(l):
             print(white(
                 _('the link "%s" does not exist.') % l,
                 bold=True, bg_color='red'
             ))
             continue
         if self.db.delete_link(l):
             print(white(
                 _('the link "%s" has been deleted.') % l,
                 bold=True, bg_color='green'
             ))
             is_removed = True
     return is_removed
def _print_distribution_details(details):
    """Print distribution details."""
    output = bytearray()
    output += ("\n" +
               colored.white("""Configured Distribution:""", bold=True) +
               "\n").encode()
    output += _format_distribution_details(details, color=True).encode()

    printer.unicode_safe(output.decode("utf-8"))
Beispiel #20
0
def scrape_mixcloud_url(mc_url, num_tracks=sys.maxsize, folders=False, custom_path=''):
    """
    Returns:
        list: filenames to open

    """

    try:
        data = get_mixcloud_data(mc_url)
    except Exception as e:
        puts_safe(colored.red("Problem downloading ") + mc_url)
        print(e)
        return []

    filenames = []

    track_artist = sanitize_filename(data['artist'])
    track_title = sanitize_filename(data['title'])
    track_filename = track_artist + ' - ' + track_title + data['mp3_url'][-4:]

    if folders:
        track_artist_path = join(custom_path, track_artist)
        if not exists(track_artist_path):
            mkdir(track_artist_path)
        track_filename = join(track_artist_path, track_filename)
        if exists(track_filename):
            puts_safe(colored.yellow("Skipping") + colored.white(': ' + data['title'] + " - it already exists!"))
            return []
    else:
        track_filename = join(custom_path, track_filename)

    puts_safe(colored.green("Downloading") + colored.white(
        ': ' + data['artist'] + " - " + data['title'] + " (" + track_filename[-4:] + ")"))
    download_file(data['mp3_url'], track_filename)
    if track_filename[-4:] == '.mp3':
        tag_file(track_filename,
                 artist=data['artist'],
                 title=data['title'],
                 year=data['year'],
                 genre="Mix",
                 artwork_url=data['artwork_url'])
    filenames.append(track_filename)

    return filenames
Beispiel #21
0
def console_runner(suite, variables=None, debug=False,
                   display_variables=False, quiet=False):
    logger = logging.getLogger(__name__)
    failed_counter = 0

    if not variables:
        variables = {}

    if not quiet:
        puts(colored.white('-' * 80))
        puts(colored.white('P - passed assertions, F - failed assertions'
                           ', V - extracted variables'))
        puts(colored.white('-' * 80))

    tests = suite['requests']
    for test_name in sorted(suite['requests'].keys()):
        test = tests[test_name]
        result = test_request(test, variables)
        logger.debug(result)
        if result['valid']:
            test_name = u"%s [P%d,F%d,V%d]" % (
                test_name,
                len(result['passed_assertions']),
                len(result['failed_assertions']),
                len(result['variables']),
            )
            if not quiet:
                line = u"✓ " + test_name
                if display_variables:
                    line += " " + str(result['variables'])
                puts(colored.green(line))
        else:
            failed_counter += 1
            if not quiet:
                puts(colored.red(
                    u"✗ " + test_name +
                    u" (" +
                    u" ∥ ".join(result['failed_assertions']) + ")"
                ))

    if not quiet:
        puts(colored.white('-' * 80))

    return failed_counter
Beispiel #22
0
def gosub(cmd, on_err=True, verbose=True):
    """ Run a shell command and return the output """
    if verbose:
        print("-- Executing `%s`" % white(cmd))
    shell = isinstance(cmd, basestring)
    proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=shell)
    out, err = proc.communicate()
    ret = proc.returncode
    if on_err:
        msg = '%s:\n' % on_err if isinstance(on_err, basestring) else ''
        assert ret==0, msg + (err or out)
    return out, err, ret
Beispiel #23
0
    def run(self, new_circuits=None):
        if new_circuits == None:
            
            # SELECT id FROM circuits
            all_circuits = Circuit.objects.all()
        else:
            #all_circuits = self.session.query(Circuit).order_by((Circuit.id).desc()).limit(new_circuits).all()
            pass
    
        
        # SELECT id FROM places
        all_places = Place.objects.all()

        # Put places ids on array
        places_ids = []
        for tp in all_places:
            places_ids.append(tp.id)
        
        session_counter = 0
        print colored.white("Populating places for circuits:")
        for ct in progress.bar(all_circuits):

            num_places = Cumulative_vec_distr(places_x_circuit)
            what_places = random.sample(places_ids,num_places)

            for item in xrange(num_places):

                Ct_St = CircuitStop(circuit=ct,
                    place=Place.objects.get(id=what_places[item]),
                    position=1
                )

                Ct_St.save()
                session_counter += 1

                if session_counter >= 5000:            
                    transaction.commit() 
                    session_counter = 0

        transaction.commit()
Beispiel #24
0
 def flush(self, forced=['']):
     """ CMD: Purge the entire Database """
     if forced[0] == 'forced':
         flush_choice = _('Y')
     else:
         print(white(
             _(
                 "You're about to empty the entire Database."
             ) + _(
                 "Are you sure [Y/n] ?"
             ),
             bold=True, bg_color='red'
         ), end='')  # noqa
         flush_choice = input(' ')
     if flush_choice == _('Y'):
         if self.db.flush():
             print(white(
                 _("Database entirely flushed."),
                 bold=True, bg_color='green'
             ))
             return True
     return False
Beispiel #25
0
    def save(self):
        # TODO: Subtitle support (if exist locally)
        if not self.data:
            puts(colored.red('This video will not be imported!'))
            return

        puts(colored.white('The following data has been extracted:', bold=True))
        for key, value in self.data.items():
            if key in ['title', 'released', 'genre']:
                title = "{:>10}: ".format(key.capitalize())
                puts(colored.green(title) + colored.yellow(value))

        self.set_video_type()
        puts(colored.white("\nThe video will archive as:", bold=True))
        puts(colored.green("{:>10}: ".format("From")) + colored.yellow(self.old_video_path))
        puts(colored.green("{:>10}: ").format("To") + colored.yellow(self.new_video_path))
        if click.confirm("\nIs this OK?"):
            record(self.data)
            self.cp_video()

            if self.poster:
                self.get_poster()
    def run(self):
        all_users = SimUser.objects.all()
        
        session_counter = 0
        print colored.white("Generating user category follow:")
        for usr in progress.bar(all_users):
            how_many_categories = Cumulative_vec_distr(categories_x_user)

            what_categories = []
            if usr.gender == 1 or usr.gender == 3:
                for i in xrange(how_many_categories):
                    cgry = Cumulative_vec_distr(choose_categorie_h)    
                    while cgry in what_categories:
                        cgry = Cumulative_vec_distr(choose_categorie_h)

                    what_categories.append(cgry)
            else:
                for i in xrange(how_many_categories):
                    cgry = Cumulative_vec_distr(choose_categorie_m)    
                    while cgry in what_categories:
                        cgry = Cumulative_vec_distr(choose_categorie_m)

                    what_categories.append(cgry)

            for i in xrange(len(what_categories)):
                ct_fl = CircuitCategoryFollow(
                    user= usr.user,
                    category=what_categories[i] 
                )

                ct_fl.save()
                session_counter += 1

                if session_counter > 5000:
                    session_counter = 0
                    transaction.commit()

        transaction.commit()
Beispiel #27
0
def scrape_audiomack_url(mc_url, num_tracks=sys.maxsize, folders=False):
    """

    Returns filenames to open.

    """

    try:
        data = get_audiomack_data(mc_url)
    except Exception as e:
        puts(colored.red("Problem downloading ") + mc_url)
        print(e)

    filenames = []

    track_artist = sanitize_filename(data['artist'])
    track_title = sanitize_filename(data['title'])
    track_filename = track_artist + ' - ' + track_title + '.mp3'

    if folders:
        if not exists(track_artist):
            mkdir(track_artist)
        track_filename = join(track_artist, track_filename)
        if exists(track_filename):
            puts(colored.yellow("Skipping") + colored.white(': ' + data['title'] + " - it already exists!"))
            return []

    puts(colored.green("Downloading") + colored.white(': ' + data['artist'] + " - " + data['title']))
    download_file(data['mp3_url'], track_filename)
    tag_file(track_filename,
            artist=data['artist'],
            title=data['title'],
            year=data['year'],
            genre=None,
            artwork_url=data['artwork_url'])
    filenames.append(track_filename)

    return filenames
def diagnose(lab, component):

    component_diagnostics = []

    if component == 'all':
        component_diagnostics.append(KeystoneDiagnostics(lab))
    elif component == 'keystone':
        component_diagnostics.append(KeystoneDiagnostics(lab))

    with progress.Bar(expected_size=len(component_diagnostics) * 2) as bar:
        for diagnostics in component_diagnostics:
            bar.show(1)
            diagnostics.execute()
            bar.show(1)

    for diagnostics in component_diagnostics:
        for d in diagnostics.diagnosis():
            if d[1][0] == "OK":
                puts(colored.white(d[0], bold=True) +
                     ' -- %s %s' % (d[1][1], colored.green('OK')))
            elif d[1][0] == "FAILED":
                puts(colored.white(d[0], bold=True) +
                     ' -- %s %s' % (d[1][1], colored.red('FAIL')))
Beispiel #29
0
                    def download_track(track, album_name=u''):
    
                        hard_track_url = get_hard_track_url(track['id'])

                        # We have no info on this track whatsoever.
                        if not 'title' in track:
                            return None

                        # May not have a "full name"
                        name = track['user']['full_name']
                        if name == '':
                            name = track['user']['username']

                        filename = sanitize_filename(name + ' - ' + track['title'] + '.mp3')

                        # Skip already downloaded track.
                        if filename in filenames:
                            return None

                        if hard_track_url:
                            puts(colored.green("Scraping") + colored.white(": " + track['title']))
                        else:
                            # Region coded?
                            puts(colored.yellow("Unable to download") + colored.white(": " + track['title']))
                            return None

                        filename = download_file(hard_track_url, filename)
                        tag_file(filename,
                                 artist=name,
                                 title=track['title'],
                                 year=track['created_at'][:4],
                                 genre=track['genre'],
                                 album=album_name,
                                 artwork_url=track['artwork_url'])

                        return filename
Beispiel #30
0
    def run(self, new_users=None):   
     
        if new_users == None:        
            #SELECT id, circuits_to_create FROM users
            #WHERE circuits_to_create > 0;
            all_users = SimUser.objects.filter(circuits_to_create__gt = 0)
        else:
            #all_users = SimUser.objects.order_by((SimUser.id).desc()).limit(new_users)
            pass
    
        cct_name = 'circuit_'
        cct_count = 0
        new_circuits = 0

        session_counter = 0
        print colored.white("Generating circuits:")
        for usuario in progress.bar(all_users):
            for i_circuit in xrange(usuario.circuits_to_create):

                circuit = Circuit(
                    name=cct_name + str(cct_count),
                    author=usuario.user,
                    rating=0,
                    category = random.randint(0,25)
                )    

                cct_count += 1
                session_counter += 1
                circuit.save()
                new_circuits += 1

                if session_counter >= 5000:
                    session_counter = 0
                    transaction.commit()

        transaction.commit()
Beispiel #31
0
def main():
    start_time = time.time()

    # Fetch input arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('input', help='input filename containing list of geohashes')
    parser.add_argument('--output', default='output.csv', help='output filename containing a optimized list of geohashes (default: output.csv)')

    args = parser.parse_args()

    filename = args.input

    if 'output' in args:
        output_file  = args.output
    else:
        output_file = 'output.csv'

    fp = open(output_file, "a");

    puts(colored.green('\nReading the file'))

    geohashes = read_file(filename)

    puts(colored.green(str("{:,}".format(len(geohashes))) + ' geohashes read\n'))

    time.sleep(1);

    puts(colored.red('Starting compression\n'))

    georaptor_out = compress(geohashes)


    if georaptor_out != False:

        # Output to file
        for geohash in georaptor_out:
            fp.write(geohash)

        puts(colored.red('\nCompression complete!'))

        time.sleep(1)

        puts(colored.white('\nOutput available at ' + output_file + '\n'))


    et = time.time() - start_time

    puts(colored.green('Total execution time: '+str(et)+' seconds\n'))
Beispiel #32
0
def printInfo(attack, prevDmg):
	if (attack[1] != prevDmg):
		dmg = attack[1]/100 if (attack[1] > 0 or attack[1] < 1.0) else int(attack[1]/100)
		print(colored.red('['+ str(dmg) + 'x]'))
	if attack[1] == 0:
		print(colored.blue(attack[0])) # no effect
	elif attack[1] == 25:
		print(colored.magenta(attack[0])) # not effective
	elif attack[1] == 50:
		print(colored.yellow(attack[0])) # not effective
	elif attack[1] == 100:
		print(colored.green(attack[0])) # normal effect
	elif attack[1] == 200:
		print(colored.cyan(attack[0])) # super
	else:
		print(colored.white(attack[0])) # super effective
Beispiel #33
0
    def format(self, record):
        levelname = record.levelname
        message = self.baseformatter.format(record)

        if levelname == 'DEBUG':
            return colored.white(message)
        elif levelname == 'INFO':
            return colored.cyan(message)
        elif levelname == 'WARNING':
            return colored.yellow(message)
        elif levelname == 'ERROR':
            return colored.red(message)
        elif levelname == 'CRITICAL':
            return colored.magenta(message)

        return message
Beispiel #34
0
def execute(argv):
    args = parseArgs()
    target = args.target

    puts(colored.white('Starting s3skiddie'))
    if args.invasive:
        puts(colored.white('Invasive Scan: ') + colored.red('ENABLED'))
    else:
        puts(colored.white('Invasive Scan: ') + colored.green('Disabled'))
    if args.filesearch:
        puts(colored.white('File Search: ') + colored.red('ENABLED'))
    else:
        puts(colored.white('File Search: ') + colored.green('Disabled'))
    if args.objects:
        puts(colored.white('Object Scan: ') + colored.red('ENABLED'))
    else:
        puts(colored.white('Object Scan: ') + colored.green('Disabled'))

    if args.file:
        try:
            f = open(target, "r")
            bucketlist = f.readlines()
            f.close()
            bucketlist = [x.strip() for x in bucketlist]
            puts(
                colored.cyan(
                    str(len(bucketlist)) +
                    " potential buckets loaded from file for testing."))
        except Exception as e:
            puts(colored.red("Could not open target file, " + str(e)))
            sys.exit(1)
    else:
        if target[:5] == "s3://":
            target = target[4:]
        bucketlist = [target]

    results = []
    for bucket in bucketlist:
        result = scanBucket(bucket, args.invasive, args.filesearch,
                            args.objects)
        results.append(result)

    output.writeResults(target, results, args.invasive, args.filesearch,
                        args.objects)
    puts(colored.white("All done!"))
Beispiel #35
0
def nsConsoleLogWrite(ns, msg):
    if nsGet(ns, "/etc/logConsoleAsJSON", False) is True:
        print(json.dumps(msg))
        return
    level_m = ["DBG", "INF", "WRN", "ERR", "CRT", "PNC"]
    level_c = [
        colored.white, colored.green, colored.cyan, colored.yellow,
        colored.red, colored.magenta
    ]
    print(
        level_c[msg['level']](level_m[msg['level']]),
        colored.white(
            time.strftime("[%m/%d %H:%M:%S]", time.localtime(msg['stamp']))),
        colored.yellow(msg['msg']))
    if msg['level'] == 5:
        nsConsole(ns, "DON'T PANIC !")
    return
def InitialiseAardvark():
    puts(colored.magenta("Detecting Aardvark adapters:"))

    # Find all the attached devices
    (num, ports, unique_ids) = aa_find_devices_ext(16, 16)

    with indent(2, quote=colored.cyan('|')):
        if num > 0:
            puts("%d device(s) found:" % num)

            # Print the information on each device
            for i in range(num):
                port = ports[i]
                unique_id = unique_ids[i]

                # Determine if the device is in-use
                inuse = "(avail)"
                if (port & AA_PORT_NOT_FREE):
                    inuse = "(in-use)"
                    port = port & ~AA_PORT_NOT_FREE

                # Display device port number, in-use status, and serial number
                with indent(4):
                    puts ("port = %d   %s  (%04d-%06d)" % \
                        (port, inuse, unique_id / 1000000, unique_id % 1000000))
        else:
            puts(colored.red("No devices found."))

        try:
            puts("Connecting to device on port %d." % port)
            handle = aa_open(port)
            if (handle <= 0):
                puts(
                    colored.red("Unable to open Aardvark device on port %d" %
                                port))
                puts(colored.red("Error code = " + colored.white(handle)))
                sys.exit()

            aa_i2c_pullup(handle, AA_I2C_PULLUP_BOTH)

        except:
            puts(colored.red("You may need to connect an Aardvark!"))
            sys.exit()

    puts("\n\n")
    return handle
Beispiel #37
0
    def format(self, record):
        # Call the original formatter class to do the grunt work
        result = logging.Formatter.format(self, record)

        # Put color depending on the logging level
        if record.levelno == logging.CRITICAL:
            result = colored.red(result)
        elif record.levelno == logging.ERROR:
            result = colored.red(result)
        elif record.levelno == logging.WARNING:
            result = colored.yellow(result)
        elif record.levelno == logging.INFO:
            result = colored.green(result)
        elif record.levelno == logging.DEBUG:
            result = colored.white(result)

        return result
Beispiel #38
0
def list_theme():
    """List all available Engineer themes."""
    themes = ThemeManager.themes()
    col1, col2 = map(
        max,
        zip(*[(len(t.id) + 2, len(t.root_path) + 2)
              for t in themes.itervalues()]))

    themes = ThemeManager.themes_by_finder()
    for finder in sorted(themes.iterkeys()):
        if len(themes[finder]) > 0:
            puts("%s: " % finder)
            for theme in sorted(themes[finder], key=lambda _: _.id):
                with indent(4):
                    puts(
                        columns(
                            [colored.cyan("%s:" % theme.id), col1],
                            [colored.white(theme.root_path, bold=True), col2]))
Beispiel #39
0
def cmd_import(args):
    if not os.path.exists(COMO_BATTERY_FILE):
        current_dataset = create_database()
    else:
        current_dataset = read_database()
    if os.path.exists(args.get(0)):
        import_dataset = Dataset()
        with open(os.path.expanduser(args.get(0)), "r") as import_file:
            import_dataset.csv = import_file.read()
        import_dataset.dict = map(import_format, import_dataset.dict)
        new = current_dataset.stack(import_dataset).sort('time')

        with open(COMO_BATTERY_FILE, 'w') as como:
            como.write(zlib.compress(new.json))

        puts(colored.white("battery statistics imported"))
    else:
        error("Couldn't open file: %s" % args.get(0))
Beispiel #40
0
def testPublicListBucket(idx, bucket, region):
    puts(
        colored.white('[Test ' + idx +
                      '] Checking bucket list permission (public)'))
    with indent(4, quote='   '):
        bucketObjects = unauth.listBucketContents(bucket, region)
        if bucketObjects is None:
            puts(colored.green('Permission denied for public bucket listing'))
            return {"testresult": "pass", "testdata": None}
        else:
            url = "https://" + region + ".amazonaws.com/" + bucket + "/"
            puts(
                colored.yellow('Public users can list objects in this bucket'))
            puts(
                colored.yellow(
                    str(len(bucketObjects)) + " objects found in bucket."))
            puts(colored.yellow("Nav here to see the full index: " + url))
            return {"testresult": "fail", "testdata": bucketObjects}
Beispiel #41
0
def run_kubectl(rk_technique, rk_scan_mode):
    technique_command = rk_technique.get('command')
    technique_id = rk_technique['id']
    technique_leading_to = rk_technique['leading_to']
    technique_mode = rk_technique['mode']
    technique_args = rk_technique['args']
    technique_arg_list = rk_technique.get('arg_list')
    technique_multistep = rk_technique.get('multistep')
    technique_steps = rk_technique.get('commands')
    puts(colored.white('\n'))

    with indent(4):
        puts(colored.yellow("ID:        "), newline=False), puts(colored.white("%s" % technique_id))
        puts(colored.yellow("Technique: "), newline=False), puts(colored.white("%s" % rk_technique['name']))
        puts(colored.yellow("Command:   "), newline=False), puts(colored.white("%s" % technique_command))

        if rk_scan_mode == 'all' or technique_mode == rk_scan_mode:
            if not technique_args:

                if not technique_multistep:

                    out, err = kubectl_subproc(technique_command)
                    kubectl_print(out, err, technique_mode, technique_leading_to)

                else:
                    for cmd_step in technique_steps:

                        out, err = kubectl_subproc(cmd_step)
                        kubectl_print(out, err, technique_mode, technique_leading_to)
                        time.sleep(2)

            else:
                with indent(4):

                    puts(colored.white('\n'))
                    puts(colored.red("✘  The command requires specific parameters:"))
                    puts(colored.white('\n'))

                    for arg in technique_arg_list:
                        x = input("         %s:" % arg)
                        technique_command = technique_command.replace("$%s" % arg, x)

                    puts(colored.green("✔  command updated, running: ", technique_command))
                    out, err = kubectl_subproc(technique_command)
                    kubectl_print(out, err, technique_mode, technique_leading_to)
                    time.sleep(2)

        else:
            with indent(4):
                puts(colored.red("✘  This command mode does not match your scan mode."))
                time.sleep(2)
Beispiel #42
0
 def download_jfsfile(remote_object, tofolder=None, checksum=False):
     'Helper function to get a jfsfile and store it in a local folder, optionally checksumming it. Returns boolean'
     if tofolder is None:
         tofolder = '.'  # with no arguments, store in current dir
     total_size = remote_object.size
     if remote_object.state in (JFS.ProtoFile.STATE_CORRUPT,
                                JFS.ProtoFile.STATE_INCOMPLETE):
         puts(
             colored.red(
                 '%s was NOT downloaded successfully - Incomplete file' %
                 remote_file.name))
         return False
     topath = os.path.join(tofolder, remote_object.name)
     with open(topath, 'wb') as fh:
         bytes_read = 0
         puts(
             colored.white('Downloading: %s, size: %s \t' %
                           (remote_object.name,
                            print_size(total_size, humanize=True))))
         with ProgressBar(expected_size=total_size) as bar:
             for chunk_num, chunk in enumerate(remote_object.stream()):
                 fh.write(chunk)
                 bytes_read += len(chunk)
                 bar.show(bytes_read)
     if checksum:
         md5_lf = JFS.calculate_md5(open(topath, 'rb'))
         md5_jf = remote_object.md5
         logging.info('%s - Checksum for downloaded file' % md5_lf)
         logging.info('%s - Checksum for server file' % md5_jf)
         if md5_lf != md5_jf:
             puts(colored.blue('%s - Checksum for downloaded file' %
                               md5_lf))
             puts(colored.blue('%s - Checksum for server file' % md5_jf))
             puts(
                 colored.red(
                     '%s was NOT downloaded successfully - cheksum mismatch'
                     % remote_object.name))
             return False
         puts(
             colored.green(
                 '%s was downloaded successfully - checksum  matched' %
                 remote_object.name))
     return True
Beispiel #43
0
def legend(options):
    print
    with indent(3, quote=colored.white(' ==> ')):
        puts('Legend')

    with indent(2, quote=colored.white('   - ')):
        puts(colored.white('Titles'))
    with indent(2, quote=colored.white('     + ')):
        puts(colored.red('red \">>\" are templates (name atttribute)'))
        puts(
            colored.green(
                'green \">>\" are not templates (contact_name attribute)'))
    if not 'small' in options:
        with indent(2, quote=colored.white('   - ')):
            puts(colored.white('Attributes'))
        with indent(2, quote=colored.white('     + ')):
            puts(colored.green('green values are inherited attributes'))
            puts(colored.yellow('yellow values are defined attributes'))
Beispiel #44
0
def help():
    print('\n')

    print(
        colored.white(""" ██████╗ ██████╗ ██████╗ ███████╗██╗████████╗
██╔════╝██╔═══██╗██╔══██╗██╔════╝██║╚══██╔══╝
██║     ██║   ██║██║  ██║█████╗  ██║   ██║   
██║     ██║   ██║██║  ██║██╔══╝  ██║   ██║   
╚██████╗╚██████╔╝██████╔╝███████╗██║   ██║   
 ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝   ╚═╝   
                                             """))

    print(
        colored.cyan(
            "A CLI Script tool to help you initialize CPP files for any contest"
        ))
    print('\nCommands:\n')
    print(colored.magenta("codeit <args> <filename/contestname>\n"))
    print(colored.red('Args list\n'))
    print(
        colored.yellow("-h -------------------------- " +
                       colored.blue("To display help menu")))
    print(
        colored.yellow("-i <contest> ----------------" +
                       colored.blue("To initialize a contest directory")))
    print(
        colored.yellow("-i -b <contest> ------------- " + colored.blue(
            "To initialize a contest directory for practice and beginner level"
        )))
    print(
        colored.yellow("-i <args> -ne <contest> ----- " + colored.blue(
            "To initialize a contest directory without error.txt file")))
    print(
        colored.yellow("-i <args> -t2 <contest> ----- " + colored.blue(
            "To initialize a contest directory and use 2nd template without error.txt file"
        )))
    print(
        colored.yellow("-i -n <file> ---------------- " +
                       colored.blue("To initialize only a single file")))
    print(
        colored.yellow("-v -------------------------- " +
                       colored.blue("To print version number")))
Beispiel #45
0
def testPublicReadBucketACL(idx, bucket, region):
    puts(
        colored.white('[Test ' + idx +
                      '] Checking bucket ACL read permission (public)'))
    with indent(4, quote='   '):
        bucketACL = unauth.getBucketACL(bucket, region)
        if bucketACL is None:
            puts(
                colored.green(
                    'Permission denied for reading public bucket ACL'))
            return {"testresult": "pass", "testdata": None}
        else:
            url = "https://" + region + ".amazonaws.com/" + bucket + "/?acl"
            puts(colored.red("Public users may read this bucket's ACL"))
            puts(
                colored.red(
                    str(len(bucketACL)) +
                    " ACL grants found attached to this bucket"))
            puts(colored.red("Nav here to see the ACL: " + url))
            return {"testresult": "fail", "testdata": bucketACL}
Beispiel #46
0
    def apply(self):
        self.puts(colored.blue("Applying project..."))
        context = self.get_initial_context()
        context.update(self.collect_parameters())

        for (number, name, filename, template_type) in self.steps():
            with indent(2):
                puts(colored.cyan("{} ({})".format(filename, template_type)))
            with indent(4):
                if self.debug:
                    puts(colored.white(u"✸ Applying template {} with context {}".format(filename, context)))
                getattr(self, 'apply_{}_template'.format(template_type))(name, filename, context)

        self.puts(colored.blue("Project Outputs:"))
        for k, v in six.iteritems(context):
            if k.startswith('Clioutput'):
                with indent(2):
                    puts(colored.cyan(k[9:]))
                with indent(4):
                    puts(colored.green(v))
Beispiel #47
0
def validate_branch_pull(git_service):
    with indent(4, '->'):
        if git_service.should_pull:
            puts(colored.white('Pulling branches (--git-pull flag is set)'))
            if not git_service.pull_target_branch():
                puts(
                    colored.red('Could not pull target branch ' +
                                git_service.target_branch))
                sys.exit()
            else:
                puts(
                    colored.green('Pulled target branch ' +
                                  git_service.target_branch))

            if not git_service.pull_source_branch():
                puts(
                    colored.red('Could not pull source branch ' +
                                git_service.source_branch))
                sys.exit()
            else:
                puts(
                    colored.green('Pulled source branch ' +
                                  git_service.source_branch))
Beispiel #48
0
def googleSearch(query,download,extension):
	URL_MAIN = 'https://www.google.com/search'
	HEADER = {'User-agent' : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'}
	PAYLOAD= {'q' : query, 'start' : 0, 'num': num_search}
	RESPONSE = requests.get(URL_MAIN, params = PAYLOAD, headers = HEADER)
	if (RESPONSE.status_code == 429):
		print(colored.red("[!]Status Code 429 Too Many Request."))
		time.sleep(1)
		print(colored.green("[*]Loading proxy list..."))
		print(colored.green("[*]Starting..."))
		for i in range(1,len(proxy_list)):
			proxy = next(proxy_pool)
			try:
				print(colored.green("[+]Proxy : ")+proxy)
				RESPONSE = requests.get(URL_MAIN, params = PAYLOAD, headers = HEADER, proxies={"http": proxy, "https":proxy})
				if(RESPONSE.status_code == 200):
					print(colored.green("[+]Proxy found!"))
					break
			except:
				print(colored.red("[!]Connection error, Switching proxy..."))
				continue
	SOUP = BeautifulSoup(RESPONSE.content, features="lxml")
	LINKS = SOUP.findAll(class_='rc')
	bar = progressbar.ProgressBar(maxval=len(LINKS), widgets=[progressbar.Bar('=', '[', ']'), ' ', progressbar.Percentage()])
	bar.start()
	PROGRESS_BAR=0
	for link in LINKS:
		bar.update(PROGRESS_BAR+1)
		print(colored.white('\nGetting urls: %s\n'%link.a.get('href')[:50]), end="")
		report.write(str(PROGRESS_BAR+1)+". "+str(link.a.get('href'))+"\n")
		if (download == True and confirmation_download.lower() == "yes"):
			os.system("wget "+str(link.a.get('href'))+" -P "+path+"/file_dork_scan/"+extension)
		PROGRESS_BAR = PROGRESS_BAR+1
		time.sleep(0.3)
		if (PROGRESS_BAR != len(LINKS)):
			print ("\033[A                             \033[A")
			print ("\033[A                             \033[A")
Beispiel #49
0
class PlaceGenerator(object):
    """
    Generates Places form file places.txt populated with Google Places
    """
    def __init__(self):
        self.places_file = 'places.txt'

    @transaction.commit_manually
    def run(self):
        try:
            places = open(self.places_file, 'r').readlines()
        except IOError, e:
            print e

        actual_places = []
        for plc in places:
            places.pop()
            places.pop()
            places.pop()
            places.pop()  # LNG:
            places.pop()  # LAT:
            place_name = places.pop()  # NAME:
            places.pop()
            actual_places.append(place_name)

        session_counter = 0
        print colored.white("Generating places:")
        for pls in progress.bar(actual_places):
            place = Place(name=pls)
            session_counter += 1
            place.save()

            if session_counter >= 5000:
                session_counter = 0
                transaction.commit()

        transaction.commit()
Beispiel #50
0
def get_commit(token):

    magic_num = random.randint(1, 100987)
    u = requests.get(base_url + 'users?since=' + str(magic_num),
                     auth=GitHub_Auth(token))
    users = u.json()
    user = users[0]['login']

    # get the repo based on user
    r = requests.get(base_url + 'users/' + user + '/repos',
                     auth=GitHub_Auth(token))
    repos = r.json()
    repo = repos[0]['name']

    # get the commit based on repo
    c = requests.get(base_url + 'repos/' + user + '/' + repo + '/commits',
                     auth=GitHub_Auth(token))
    commits = c.json()
    commit = commits[0]['sha']

    # get the commit message based on the sha of commit
    m = requests.get(base_url + 'repos/' + user + '/' + repo + '/commits/' +
                     str(commit),
                     auth=GitHub_Auth(token))
    messages = m.json()
    commiter = messages['commit']['author']['name']
    message = messages['commit']['message']

    if "Initial commit" in message:
        print(
            emoji.emojize(commiter + ' Made an ' + message +
                          ' :confetti_ball:'))
    else:
        print(
            colored.green('Here\'s a random commit from ' +
                          colored.yellow(commiter + ':', bold=True) + '\n',
                          bold=True) + colored.white(message, bold=True))
Beispiel #51
0
    def _collect_lambda_module_content(self,
                                       destination,
                                       go_target_arch='amd64',
                                       go_target_os='linux'):
        root = os.path.join(self.get_root(), self.settings['code'])
        with utils.cd(root):
            commands = self._get_build_command(destination)
            if hasattr(commands, '__call__'):
                commands()
                return
            elif isinstance(commands, six.string_types):
                commands = [commands]

            for command in commands:
                command = command.format(
                    target=destination,
                    pip_path=self._pip_path(),
                    npm_path=self._npm_path(),
                    gradle_path=self._gradle_path(),
                    pip_install_extra=self._pip_install_extra(),
                    npm_install_extra=self._npm_install_extra(),
                    gradle_build_extra=self._gradle_build_extra(),
                    project_path=self.project.path,
                    project_name=self.project.name,
                    lambda_name=self.name,
                    go_target_os=go_target_os,
                    go_target_arch=go_target_arch,
                )
                if self.project.debug:
                    with indent(4):
                        self.project.puts(colored.white(command))
                out = subprocess.check_output(command,
                                              shell=True,
                                              stderr=subprocess.STDOUT)
                if self.project.debug and out:
                    with indent(4):
                        self.project.puts(out)
Beispiel #52
0
class UserGenerator(object):
    """
    Generates user randomly from names.txt
    """

    #By default, there should be a 'names.txt' file in the same folder
    def __init__(self):
        self.names_file = "names.txt"

    @transaction.commit_manually
    def run(self):
        try:
            # File containing 10 000 user names obtained from Twitter
            names = open(self.names_file, 'r').readlines()

        except IOError, e:
            print e

        print colored.white("Generating users:")
        for name in progress.bar(names):
            # Create ...auth.models.User
            new_user = User(username=name)
            # Save to db
            new_user.save()

            # Create models.SimUser
            sim_user = SimUser(
                user=new_user,
                free_time_score=Cumulative_vec_distr(score_prob),
                explorer_score=Cumulative_vec_distr(score_prob),
                pop_score=Cumulative_vec_distr(score_prob),
                circuits_to_create=Cumulative_vec_distr(circuits_x_user))

            # Save to db
            sim_user.save()
        transaction.commit()
Beispiel #53
0
    def delete(self):

        if self.dry_run:
            self.puts(
                colored.yellow((
                    "\nYou are trying to delete this project's resources!\n"
                    "By default this command runs in dry-run mode. If you are ok \n"
                    "with the following resources being deleted, you can run this\n"
                    "command with --confirm to do the actual deletion.\n"
                    "\nNOTHING IS GOING TO BE DELETED!\n")))
            self.puts(
                colored.blue("The following resources would be deleted..."))
        else:
            self.puts(colored.blue("Deleting project resources..."))

        context = self.get_initial_context()

        with indent(2):
            self.puts(
                colored.magenta(
                    "\nRegion:{Region}\nStage: {Stage}\n".format(**context)))

        for (number, name, filename, template_type) in self.steps():
            with indent(2):
                self.puts(
                    colored.cyan("{} ({})".format(filename, template_type)))
            with indent(4):
                if self.debug:
                    self.puts(
                        colored.white(
                            u"✸ Delete template {} with context {}".format(
                                filename, context)))
                getattr(self,
                        'delete_{}_template'.format(template_type))(name,
                                                                    filename,
                                                                    context)
Beispiel #54
0
    def run(self):
        chunks = {}

        chunks['bottom'] = (self.amount * 60) / 100
        chunks['middle'] = (self.amount * 30) / 100
        chunks['top'] = self.amount - (chunks['bottom'] + chunks['middle'])

        bottom_vals = [random.randint(1, 80) for i in range(chunks['bottom'])]
        bottom = []

        print colored.white("Generating topics level 0:")
        for elem in progress.bar(bottom_vals):
            new_topic = Topic()
            bottom.append(new_topic)

            new_topic.save()
        middle = []
        transaction.commit()

        print colored.white("Generating topics level 1:")
        for i in progress.bar(range(chunks['middle'])):
            children = random.sample(bottom, random.randint(8, 11))

            new_topic = Topic()
            new_topic.save()

            for child in children:
                new_topic.parent.add(child)

            middle.append(new_topic)

        print colored.white("Generating topics level 2:")
        for i in progress.bar(range(chunks['top'])):
            children = random.sample(middle, random.randint(4, 7))

            new_topic = Topic()
            new_topic.save()

            for child in children:
                new_topic.parent.add(child)

        transaction.commit()
Beispiel #55
0
def show_help():
    """
        Method for showing help in the daemon CLI
    :return:
    """
    llogger = local_logger.LocalLogger()
    llogger.log_call(sys._getframe().f_code.co_name)
    with indent(4, quote='>>'):
        puts(colored.white("Daemon command list"))
    with indent(5, quote='1.'):
        puts(colored.white("start - Starts the swarmrob daemon."))
    with indent(5, quote='2.'):
        puts(
            colored.white(
                "status - Prints the current status of the swarmrob daemon."))
    with indent(5, quote='3.'):
        puts(colored.white("stop - Stops the swarmrob daemon."))
    with indent(5, quote='4.'):
        puts(colored.white("check - Checks if docker is installed correctly."))
    with indent(5, quote='5.'):
        puts(colored.white("help - Prints this help page."))
Beispiel #56
0
def show_help():
    """
        Shows the help on the swarmrob CLI

    :return:
    """
    llogger = local_logger.LocalLogger()
    llogger.log_call(sys._getframe().f_code.co_name)

    with indent(4, quote='>>'):
        puts(colored.white("Command list"))
    index = 1
    if is_master_available() is True:
        with indent(5, quote=str(index) + '.'):
            puts(
                colored.white(
                    "master - Access all master commands. Type 'swarmrob master help' for more info."
                ))
            index += 1
    with indent(5, quote=str(index) + '.'):
        puts(
            colored.white(
                "worker - Access all worker commands. Type 'swarmrob worker help' for more info."
            ))
    with indent(5, quote=str(index + 1) + '.'):
        puts(
            colored.white(
                "daemon - Access all daemon commands. Type 'swarmrob daemon help' for more info."
            ))
    with indent(5, quote=str(index + 2) + '.'):
        puts(
            colored.white(
                "check - Checks for missing usage requirements and installs them if possible."
            ))
    with indent(5, quote=str(index + 3) + '.'):
        puts(colored.white("help - Prints this help page."))
    print()
    return True
Beispiel #57
0
while True:
    while True:
        print ("%s...waiting...%s" % (fg(46), attr(0)))
        newsocket, fromaddr = bindsocket.accept()
        try:
            connstream = ssl.wrap_socket(newsocket, server_side=True, certfile="certificate.pem", keyfile="private_key")
        except ssl.SSLError:
            print ("%s%s!!!WARNING!!! BAD CLIENT (or other SSL problem)%s" % (fg(9),attr(1),attr(0)))
            break
        print ("%s...probably good client...%s" % (fg(46), attr(0)))
        time.sleep(2)
        ExecIN("clear")
        cType = RecvData()
        print ("%s----[new-client] " + str(fromaddr) + " :: " + cType + "%s") % (fg(202),attr(0))
        while True:
            inText = raw_input(colored.white('<T2B:')+colored.yellow(cType+'> '))
            if inText.startswith("download"):
                SendData(inText)
                DownloadFILE(inText.split(" ")[1])
            elif inText.startswith("upload"):
                SendData(inText)
                UploadFILE(inText.split(" ")[1])
                chunk = RecvData()
            elif inText.startswith("!"):
		        ExecIN(inText.split("!")[1])
            elif inText.startswith('s-wifi'):
                SendData("get-inferfaces")
                # retrieve list of wireless card, if present scan else print error and go on
                print (("%s"+RecvData()+"%s") % (fg(6),attr(0)))
                card = raw_input("[*] Enter wifi card name: ")
                if card == "none":
Beispiel #58
0
def list(nc, filtre, options):
    contacts_founded = []
    contacts_template_founded = []

    contacts_filtered = []
    contacts_template_filtered = []

    try:
        contacts = nc['all_contact']
    except KeyError:
        with indent(3, quote=colored.white(' ==> ')):
            puts("No contact")
        sys.exit(0)
    except Exception as err:
        with indent(3, quote=colored.white(' ==> ')):
            puts("Something went wront (%)" % err)
        sys.exit(1)

    for contact in contacts:
        filtered = False
        for element in filtre:
            if element in contact.keys():
                try:
                    filtre_pattern = re.compile(filtre[element])
                except:
                    with indent(3, quote=colored.red(' >> ')):
                        puts('Regexp error')
                    sys.exit(1)
                if not filtre_pattern.match(contact[element]):
                    filtered = True
                    break
                else:
                    filtered = False
            else:
                filtered = True
                break

        if not filtered:
            if contact.has_key('register'):
                if contact['register'] == 0:
                    contacts_founded.append(contact)
                else:
                    contacts_template_founded.append(contact)
            else:
                contacts_founded.append(contact)
        else:
            if contact.has_key('register'):
                if contact['register'] == 0:
                    contacts_filtered.append(contact)
                else:
                    contacts_template_filtered.append(contact)
            else:
                contacts_filtered.append(contact)

    contacts_founded = sorted(
        contacts_founded,
        key=lambda k: k['meta']['defined_attributes']['contact_name'])
    contacts_template_founded = sorted(contacts_template_founded,
                                       key=lambda k: k['name'])

    contacts_filtered = sorted(
        contacts_filtered,
        key=lambda k: k['meta']['defined_attributes']['contact_name'])
    contacts_template_filtered = sorted(contacts_template_filtered,
                                        key=lambda k: k['name'])

    with indent(3, quote=colored.white(' ====> ')):
        puts("Contacts founded")

    if contacts_template_founded:
        for contact in contacts_template_founded:
            with indent(3, quote=colored.red(' >> ')):
                puts("%s" % contact['name'])
            if not 'small' in options:
                for key, value in sorted(contact.items()):
                    if key != 'meta':
                        if key in contact['meta']['inherited_attributes']:
                            with indent(3, quote=colored.white('    | ')):
                                puts("%s: %s" %
                                     (colored.blue(key), colored.green(value)))
                        else:
                            with indent(3, quote=colored.white('    | ')):
                                puts(
                                    "%s: %s" %
                                    (colored.blue(key), colored.yellow(value)))

    if contacts_founded:
        for contact in contacts_founded:
            with indent(3, quote=colored.green(' >> ')):
                puts("%s" % contact['contact_name'])
            if not 'small' in options:
                for key, value in sorted(contact.items()):
                    if key != 'meta':
                        if key in contact['meta']['inherited_attributes']:
                            with indent(3, quote=colored.white('    | ')):
                                puts("%s: %s" %
                                     (colored.blue(key), colored.green(value)))
                        else:
                            with indent(3, quote=colored.white('    | ')):
                                puts(
                                    "%s: %s" %
                                    (colored.blue(key), colored.yellow(value)))

    with indent(3, quote=colored.white(' ==> ')):
        puts("Total: %s" %
             (len(contacts_founded) + len(contacts_template_founded)))

    if 'show_filtered' in options:
        print('')
        with indent(3, quote=colored.white(' ====> ')):
            puts("Contacts filtered")

        if contacts_template_filtered:
            for contact in contacts_template_filtered:
                with indent(3, quote=colored.red(' >> ')):
                    puts("%s" % contact['name'])

        if contacts_filtered:
            for contact in contacts_filtered:
                with indent(3, quote=colored.green(' >> ')):
                    puts("%s" % contact['contact_name'])

        with indent(3, quote=colored.white(' ==> ')):
            puts("Total: %s" %
                 (len(contacts_filtered) + len(contacts_template_filtered)))
Beispiel #59
0
def charsheet():
    #XP display
    clear()
    exp = contents[0:8]
    level = exp[4]
    expint = int(exp[4:8])
    print(' ')
    print(' ')
    print(' ')
    print(' ')
    print(' ')
    print(' ')
    print(' ')
    print(' ')
    print(colored.red("Character Name: ") + colored.blue(charfile))
    print(' ')
    print(colored.yellow(exp))
    print(colored.yellow('Level: ') + colored.yellow(level))

    stripn = len(charfile)
    stripf = 16 + stripn

    contents1 = contents.replace(contents[:stripf], '')

    print(' ')

    stripstat = 86
    contents2 = contents1.replace(contents1[:stripstat], '')

    inventype = contents2[0:10]
    invlook = stripf + 86 + 11
    actinv = contents.replace(contents[:invlook], '')
    inventory = actinv.split(",")

    statlist = contents1[0:86]
    statlist2 = statlist.split(',')

    hp = 5
    hpcalc = statlist2[2]
    hpcalc2 = hpcalc[11]
    hpcalc3 = int(hpcalc2)
    hpfinal = hpcalc3 * hp

    if hpfinal > 24:
        print('HP:' + colored.green(str(hpfinal)))

    elif hpfinal > 14:
        print('HP: ' + colored.yellow(str(hpfinal)))

    elif hpfinal > 1:
        print('HP: ' + colored.red(str(hpfinal)))

    print(' ')
    print(colored.white(statlist2[0]))  #strength
    print(colored.white(statlist2[1]))  #perception
    print(colored.white(statlist2[2]))  #endurance
    print(colored.white(statlist2[3]))  #charisma
    print(colored.white(statlist2[4]))  #inteligence
    print(colored.white(statlist2[5]))  #agility
    print(colored.white(statlist2[6]))  #luck

    print(' ')
    print(' ')

    if inventype == "INVENTORY4":
        print("Inventory size: Survival (6 Slots)")
        print(' ')
        print(inventory)

    if inventype == "INVENTORY2":
        print("Inventory size: Medium (15 Slots)")
        print(' ')
        print(inventory)

    if inventype == "INVENTORY1":
        print("Inventory size: Light (10 Slots)")
        print(' ')
        print(inventory)

    if inventype == "INVENTORY3":
        print("Inventory size: Heavy (20 Slots)")
        print(' ')
        print(inventory)

    menu()
def logMessage(text):
    puts(colored.white(text))