コード例 #1
0
ファイル: blame.py プロジェクト: notlxb/gitstats-1
 def __init__(self, rawgitblame):
     self.hash = None
     self.author = Author(None, None)
     self.committer = Author(None, None)
     self.summary = None
     self.filename = None
     self.content = None
     self.__parse(rawgitblame)
コード例 #2
0
def main():
    clean_code = Book("Clean Code", 12.4)
    python = Book("Python Code", 12.4)
    boob = Author("Boob", 23)
    john = Author("John", 5)
    boob.write(clean_code)
    boob.write(python)
    john.write(python)

    print(clean_code.authors)
    print(python.authors)

    ####################################
    print(john.books)
    print(boob.books)
コード例 #3
0
ファイル: api.py プロジェクト: Khrystynka/teamFinder
def get_team(user):
    logging.debug(f'In get_teams: Cookies: {request.cookies}')
    logging.debug(f'In get_t teams: session: {session}')

    if 'oauth_token' not in session.keys():
        return 'Login first'
    github = OAuth2Session(
        app.config['CLIENT_ID'], token=session['oauth_token'])
    author = Author(github, user)
    if not author:
        logging.debug( 'User login is not valid')
    team_comments = author.get_team_by_pullrequests()
    logging.debug(f'by comments: {team_comments}')

    team_close_commits = author.get_team_by_close_commits()
    logging.debug(f'by close commits: {team_close_commits}')

    team_followers = author.get_followers()
    logging.debug(f'by followers: {team_followers}')

    team_following = author.get_following()
    team = combineTeams(team_followers, team_following,
                        team_close_commits, team_comments, user)
    logging.debug(f'all teammates: {team}')

    resp = jsonify({'team': team})

    resp.headers['Access-Control-Allow-Credentials'] = "true"
    resp.headers['Access-Control-Allow-Origin'] = URL

    return resp
コード例 #4
0
 def __init__(self, appInfo, author):
     super(EditingAuthorMenu, self).__init__()
     loadUi('adding_author.ui', self)
     this_author = Author()
     for book in author.book_list:
         this_author.add_book(book)
     for genre in author.genre_list:
         this_author.add_genre(genre)
     appInfo.library.delete_author(author.name)
     self.lineEdit.setText(author.name)
     self.lineEdit_2.setText(str(author.birth_year))
     self.lineEdit_3.setText(str(author.death_year))
     self.textEdit.setText(author.description)
     self.pushButton_8.clicked.connect(self.closing)
     self.pushButton_9.clicked.connect(
         lambda: self.adding(appInfo, this_author, author.name))
     self.pushButton_5.clicked.connect(
         lambda: self.adding_book(this_author, appInfo))
     self.pushButton_6.clicked.connect(
         lambda: self.adding_genre(this_author))
     self.pushButton_10.clicked.connect(
         lambda: self.delete_book(this_author))
     self.pushButton_11.clicked.connect(
         lambda: self.delete_genre(this_author))
     self.update_tables(this_author)
コード例 #5
0
ファイル: xmlParser.py プロジェクト: suqianwang/Databases
    def __init__(self):
        # class attributes
        self.CurrentData = ""
        self.key = ""
        self.author = ""
        self.title = ""
        self.journal = ""
        self.booktitle = ""
        self.year = 0
        self.type = ""

        # class objects
        self.article = Article()
        self.inproceedings = Inproceedings()
        self.authorObject = Author()

        # help with concat strings
        self.strhelper = StringHelper()
        self.authorStringList = []
        self.titleStringList = []
        self.journalStringList = []
        self.booktitleStringList = []

        #
        self.dbConnector = DBConnector
コード例 #6
0
 def __init__(self, title: str, isbn: str, price: str, author_name: str,
              author_mail: str) -> None:
     self._title = title
     self._isbn = isbn
     self._price = price
     self._author = Author(author_name, author_mail)
     self._author_mail = author_mail
コード例 #7
0
ファイル: views.py プロジェクト: itucsdb1920/itucsdb1920
def author_edit_page(author_id):
    searchform = SearchForm()
    db = current_app.config["db"]
    author = db.get_author_by_id(author_id)
    if author is None:
        abort(404)
    if not current_user.is_admin:
        abort(401)
    form = AuthorForm()
    if form.validate_on_submit():
        name = form.data["name"]
        description = form.data["description"]
        photo = form.data["photo"]
        author_ = Author(id=author_id,
                         name=name,
                         description=description,
                         photo=photo)
        db.update_author(author_)
        flash("Author updated successfully.")
        return redirect(url_for("author_page", author_id=author_id))
    form.name.data = author.name
    form.description.data = author.description if author.description else ""
    form.photo.data = author.photo if author.photo else ""
    return render_template("author_edit.html",
                           form=form,
                           searchform=searchform)
コード例 #8
0
ファイル: main.py プロジェクト: CongoCash/Rocket
def blog_manager(user, blog_posts, authors):

    # Ask for input from the user which we can check against later. Convert to lowercase to check for fewer cases
    action = raw_input(
        'Would you like to (A)dd a blog post, (S)ee existing posts or (Q)uit? '
    ).lower()

    if action == 'a':
        is_author = raw_input(
            'Are you the author of this post? (y/n) ').lower()
        if is_author == 'y':
            author = user
        else:
            author_name = raw_input('What is the name of the author? ')
            author = Author(author_name)
            authors.append(author)
        title = raw_input('What is the title of the blog post? ')
        published_date = raw_input('When was this published? ')
        b = author.write_blog_post(title, published_date)
        blog_posts.append(b)

        print 'Congratulations! You added post {} for {}'.format(b, author)

        blog_manager(user, blog_posts, authors)
    elif action == 's':
        print blog_posts
        blog_manager(user, blog_posts, authors)
    elif action == 'q':
        print 'Thanks for using the blog!'
    else:
        print 'Sorry, I do not understand what you want.'
        blog_manager(user, blog_posts, authors)
コード例 #9
0
 def edit_author(self, name, birth_year=0, death_year=0, description=None):
     this_author = Author(name, birth_year, death_year, description)
     if this_author not in self._author_list:
         return False
     self.delete_author(this_author.name)
     self._author_list.append(this_author)
     return True
コード例 #10
0
ファイル: db.py プロジェクト: tiagonc96/socialbustl
def author_iterator(n_messages):
  return (
    Author(data["value"]["user"],data["value"]["latest_tweets"]) for data
    in get_list_of_messages_from_unclassified_users(n_messages).find(
      {"value.count": {"$gte": n_messages}},
      {"_id": 0, "value.count": 1, "value.latest_tweets": 1, "value.user": 1}
    )
  )
コード例 #11
0
ファイル: zhihutu.py プロジェクト: Zing22/zhihutu
def init():
    print("Begin initialize...")
    db_connection = DBConnection()
    url_token_set = db_connection.restore_url_token()

    origin = Author(ORIGIN_URL_TOKEN, COOKIES_STR, ORIGIN_NAME, ORIGIN_GENDER,
                    ORIGIN_AVATAR_URL_TEMPLATE)
    return db_connection, url_token_set, origin
コード例 #12
0
 def update_book(self, book_id, book):
     with dbapi2.connect(self.db_url) as connection:
         cursor = connection.cursor()
         if book.author is not None:
             if self.get_author(book.author) is None:
                 book.author = self.add_author(Author(name=book.author))
             else:
                 self.update_author(Author(name=book.author))
                 book.author = self.get_author(book.author).id
         query = "UPDATE BOOK SET TITLE = %s, AUTHORID = %s, YR = %s, PGNUM = %s, COVER = %s, DESCRIPTION = %s WHERE (ID = %s)"
         cursor.execute(
             query, (book.title, book.author, book.year, book.pageNumber,
                     book.cover, book.description, book_id))
         connection.commit()
         self.delete_genres(book_id)
         for genre in book.genres:
             self.add_genre(book_id, genre)
コード例 #13
0
ファイル: zhihutu.py プロジェクト: Zing22/zhihutu
def crawl_one(url_token, db_connection, cookies_str):
    profile = load_profile(url_token, cookies_str)
    if not profile:
        return False
    author = Author(url_token, cookies_str, profile['name'], profile['gender'],
                    profile['avatar_url_template'])
    author.load_answers()
    db_connection.save_author(author)
    return True
コード例 #14
0
ファイル: client.py プロジェクト: critcortex/goodreads-py
 def author_by_id(self, **query_dict):
     """
     Get information about an author from their id.
     Input example: { 'id' : '2546' }
     """
     goodreads_request = GoodreadsRequest("author/show.xml", query_dict,
                                          self)
     response = goodreads_request.request()
     return Author(response['author'])
コード例 #15
0
ファイル: authors.py プロジェクト: Cbhihe/pyDojo
 def delete(self, conn):
     for row in self.select(conn):
         author = Author(
             row['id'],
             row['name'],
             row['birth'],
         )
         author.delete(conn)
         print("")
コード例 #16
0
    def __init__(self, logstring):
        loglist = logstring.split("\n")
        self.hash = loglist[0]
        self.subject = loglist[2]
        self.author = Author(loglist[3], loglist[4])
        self.committer = Author(loglist[5], loglist[6])

        try:
            self.date = datetime.strptime(loglist[1][:-6], "%Y-%m-%dT%H:%M:%S")
        except:
            print "Error parsing date of %s" % logstring
            raise

        try:
            self.diffstats = [Diffstat(diffstat) for diffstat in loglist[8:-1]]
        except:
            print "Error parsing diffstat of %s" % logstring
            raise
コード例 #17
0
ファイル: authors.py プロジェクト: Cbhihe/pyDojo
 def update(self, conn, field, new_value):
     for row in self.select(conn):
         author = Author(
             row['id'],
             row['name'],
             row['birth'],
         )
         setattr(author, field, new_value)
         author.save(conn)
コード例 #18
0
 def get_author(self, name):
     with dbapi2.connect(self.db_url) as connection:
         cursor = connection.cursor()
         query = "SELECT ID, DESCRIPTION, PHOTO FROM AUTHOR WHERE (NAME = %s)"
         cursor.execute(query, (name, ))
         try:
             id, description, photo = cursor.fetchone()
         except:
             return None
     return Author(name=name, id=id, description=description, photo=photo)
コード例 #19
0
 def parse(self, response):
     author_name = response.css('h1::text').extract_first()
     author = Author(name=author_name, songs=[])
     song_list = response.css('ul.cnt-list li a')
     for song in song_list:
         title = song.css('::text').extract_first()
         link = song.css('::attr(href)').extract_first()
         author.songs.append(
             Song(author_name, title, config.page_url + link, None))
     self.authors.append(author)
コード例 #20
0
ファイル: zhihutu.py プロジェクト: Zing22/zhihutu
def updateState(author: Author, url_token_set: set, waiting_list: Queue):
    url_token_set.add(author.url_token)
    for followee in author.followees:
        if followee['user_type'] != 'people' or\
           followee['follower_count'] < 100 or \
           followee['url_token'] in url_token_set:
            continue
        next_author = Author(followee['url_token'], COOKIES_STR,
                             followee['name'], followee['gender'],
                             followee['avatar_url_template'])
        waiting_list.put(next_author)
コード例 #21
0
 def __init__(self, author, country, imageLink, language, link, pages,
              title, year):
     self.author = []
     self.author.append(Author(author))
     self.country = country
     self.imageLink = imageLink
     self.language = language
     self.link = link
     self.pages = pages
     self.title = title
     self.year = year
コード例 #22
0
 def createAuthor():
     author = Author(authorName)
     for dirEntry in os.scandir('data'):
         _authorName = dirEntry.name.split('_-_')[0]
         if _authorName == authorName:
             try:
                 with open(dirEntry.path) as file:
                     author.loadBooks(file)
             except UnicodeDecodeError:
                 pass
     author.calcProbability()
     return author
コード例 #23
0
def addBook():
    authorNameInput = str(input('Enter author name: '))
    authorEmailInput = str(input('Enter author email: '))
    authorGenderInput = str(input('Enter author gender: '))

    bookNameInput = str(input('Enter book name: '))
    bookPriceInput = float(input('Enter book price: '))
    bookQtyInput = int(input('Enter book quantity: '))

    atInput = Author(authorNameInput, authorEmailInput, authorGenderInput)
    atList.append(atInput)
    bookList.append(Book(bookNameInput, atInput, bookPriceInput, bookQtyInput))
コード例 #24
0
def add_authors(authProfiles):
    """Add a list of authors"""
    formatted = [Author(
        name=i['name'], 
        gs_profile_id=i['gs_profile_id'], 
        affiliation=i['affiliation'], 
        interest=', '.join(i['interest'])
        ) for i in authProfiles]
    print('WRITE: %d authors to database...' % len(authProfiles))
    session.add_all(formatted)
    queue_todo(formatted, AUTHOR)
    session.commit()
コード例 #25
0
    def __get_articles_by_ids(article_ids):
        if article_ids is None or len(article_ids) == 0:
            return []
        
        Entrez.email = Article.__user_email        
        handle = Entrez.efetch( db = 'pubmed',
                                id = article_ids,
                                rettype = 'medline',
                                retmode = 'text'
                                )
             
        records = Medline.parse( handle )

        articles = []
        for record in records:
            pmid = record['PMID']
            authors = None
            
            if 'FAU' in record:
                authors = record['FAU']
            else:
                authors = ['CN']
            
            authors_objs = []
            for author in authors:
                name = author
                surname = None
                
                if ', ' in author:
                    [surname, name] = str.split(author, ', ')
                
                from author import Author
                
                if name is not None and surname is not None:
                    author_str = name + ' ' + surname
                elif name is not None and surname is None:
                    author_str = name
                elif name is None and surname is not None:
                    author_str = surname
                else:
                    author_str = ''
                    
                if(author_str not in Article.__authors_cache):
                    authors_objs.append( Author(name, surname) )
                else:
                    authors_objs.append( Article.__authors_cache[author_str])

            articles.append( Article( pmid, authors_objs ) )

        return articles
コード例 #26
0
def process_author(author, k):
	'''Given an authos soup object, collects information and books 
	for the author if they have at least k sentences throughout their books
	Parameters:
	author - an author soup object
	k - the number of sentences required
	Output: books_list - the list of books for that author
			author_path - the folder where books for that author are saved
	'''
	author_name = author.getText() #get the author name
	authorclean = ''.join(x for x in author_name.split('(')[0] if x.isalpha() or x in ' ') #leave alpha characters and spaces
	author_path = unidecode(clean_name(author_name))

	#if the author is not yet in the db
	if author_path > "Verna Draba" and not db['lab1'].find({'folder':author_path}).count():
		print(authorclean)
		#get the next sibling of the author and proceed only if it is ul
		next_sibling = author.find_next_sibling()
		if next_sibling.name != 'ul':
			return None, None
		list_of_books = author.find_next_sibling("ul") #get a list of books for the author (using the ul sibling of the h2 tag)
		if list_of_books != None: #if there is a list of books
			books = list_of_books.findAll("li", {"class" : "pgdbetext"}) #get all books
			if "Anonymous" not in authorclean and "Unknown" not in authorclean: #if author is not Anonymous or Unknown
				books_to_save, k = get_books_up_to_k_sentences(books, k)
				
				#if k has reached 0, save all the books for that author
				if k == 0:
					books_list = []
					for book in books_to_save:
						book_path = save_file(book[0], './lab1_data/'+author_path+'/', book[1]) #write the returned sentence to a file with the book name
						# books_by_author[author_path].append({'name': book[2], 'path':book_path}) #add the book to the respective author in the books_by_author dictionary
						books_list.append({'name': book[2], 'path':book_path})
					
					#get the multilingual abstracts and the literary movements
					abstracts, url_author = get_multilingual_abstracts(authorclean)

					movements = []
					if url_author != None:
						movements = get_literary_movements(url_author)
					#create and author object, record all the related the data and save it to the db
					a = Author(url_author)
					a.name = authorclean.strip()
					a.folder = author_path
					a.books = books_list
					a.abstracts = abstracts
					a.movements = movements
					out = db['lab1'].insert_one(a.__dict__)
					return books_list, author_path
	return None, None
コード例 #27
0
def add_author(authProfile):
    """Add a single author"""
    name = authProfile['name']
    gs_profile_id = authProfile['gs_profile_id']
    affiliation = authProfile['affiliation']
    interest = ', '.join(authProfile['interest'])

    if session.query(exists().where(Author.gs_profile_id == gs_profile_id)).scalar():
        return
    else:
        author = Author(name=name, gs_profile_id=gs_profile_id, affiliation=affiliation, interest=interest)
        print('WRITE: author %s to database...' % gs_profile_id)
        session.add(author)
        queue_todo(name, AUTHOR)
        session.commit()
コード例 #28
0
 def add_new_author(self, appInfo, book):
     author = Author(book.author)
     book_list = [book.name]
     appInfo.authors_database.insert_one({
         "name": book.author,
         "birth_year": 0,
         "death_year": 0,
         "description": '',
         "books": book_list,
         "genres": book.genre_list
     })
     author.add_book(book.name)
     new_window = EditingAuthorMenu(appInfo, author)
     new_window.exec_()
     self.close()
コード例 #29
0
 def adding(self, appInfo, this_book):
     if self.lineEdit.text() and self.lineEdit_2.text():
         valid = True
         if self.lineEdit_3.text():
             try:
                 int(self.lineEdit_3.text())
             except ValueError:
                 message = ErrorDialog()
                 message.label_2.setText("Year must be a digit!.")
                 message.exec_()
                 valid = False
         if valid:
             this_book.set_name(self.lineEdit.text())
             this_book.set_author(self.lineEdit_2.text())
             author = Author(self.lineEdit_2.text())
             if author not in appInfo.library.author_list:
                 author.book_list.append(this_book.name)
                 appInfo.library.add_author_object(author)
                 message = CreateAnAuthor(appInfo, this_book)
                 message.exec_()
             if self.textEdit.toPlainText():
                 this_book.set_description(self.textEdit.toPlainText())
             else:
                 this_book.set_description("Description unknown.")
             if self.lineEdit_3.text():
                 this_book.set_year(self.lineEdit_3.text())
             else:
                 this_book.set_year(0)
             if not appInfo.library.add_book_object(this_book):
                 message = ErrorDialog()
                 message.label_2.setText("This book already exists.")
                 message.exec_()
             else:
                 appInfo.books_database.insert_one({
                     "name":
                     this_book.name,
                     "author":
                     this_book.author,
                     "year":
                     this_book.year,
                     "description":
                     this_book.description,
                     "tags":
                     this_book.tag_list,
                     "genres":
                     this_book.genre_list
                 })
                 self.close()
コード例 #30
0
ファイル: main.py プロジェクト: fura-ness/spambot
def check_for_spammers(authordb, r):

    for author in get_newest_posters(r):

        saved_author = str(author.name) in authordb

        if saved_author:
            author = authordb.get(str(author.name))
        else:
            created = author.created
            author = Author(author)
            author.created = created
            authordb[str(author.username)] = author

        author.seen_at = datetime.datetime.now()

        print '+++ %s%s:' % (author.username,
                             ' (seen)' if saved_author else ''),

        if saved_author and author.possible_spammer == False:
            print '%s has been seen already and cannot be a spammer (%s)' % (
                author.username, author.stats())
            continue

        confidence, spam_profile = author.get_spammer_confidence(r)

        if confidence > 0.5:
            print "%s IS A SPAMMER: %s (%s)" % (author.username, confidence,
                                                author.stats())
            try:
                author.submit(r)
            except Exception as e:
                print 'EXCEPTION', type(e)
                print str(e)

            with open('spammers/%s' % author.username, 'a') as f:
                f.write('%s|%s|%s\n' %
                        (spam_profile.link_karma, spam_profile.comment_karma,
                         spam_profile.domains))

        elif confidence == 0.5:
            print "%s is a POSSIBLE spammer: %s (%s)" % (
                author.username, confidence, author.stats())
            with open('possible-spammers.txt', 'a') as f:
                f.write('http://www.reddit.com/user/%s\n' % author.username)

        elif confidence < 0.5:
            print 'not a spammer (%s)' % author.stats()