コード例 #1
0
ファイル: views.py プロジェクト: nelsonsequiera/gale
def index(request):
    startdate = '1970-01-01'
    enddate = Date.today()
    # retrieves all articles from the db in ascending order of publication date
    all_articles = Article.objects.filter(pub_date__range = [startdate, enddate]).order_by('-pub_date')
    
    # selects a random article from the list
    random_article = random.choice(all_articles)
    # gets the day of the article published
    day = random_article.pub_date.strftime("%A")
    
    # gets the top three articles from all articles
    topThree_articles = all_articles[:5]
    
    # retrieves 4 articles from the db in random order
    random_four = Article.objects.filter(pub_date__range = [startdate, enddate]).order_by('?')[:4]
    
    # adding contents to the dictionary
    context_dict = {}
    context_dict[ 'random_article' ] = random_article
    context_dict[ 'topThree_articles' ] = topThree_articles
    context_dict['day'] = day
    context_dict['random_four'] = random_four
    
    return render(request, 'ver1/index.html', context_dict) 
コード例 #2
0
ファイル: library_page.py プロジェクト: RehamEzzat/Musicly
    def add_song(self):
        name = input("Enter name: ")
        url = input("Enter URL: ")
        headers = ["Band/Artist Name"]
        bands_list = self._db.get_all_bands()
        artists_list = self._db.get_all_artists()
        self.print_list(headers, bands_list)
        self.print_attrs(["----------"], artists_list)
        band_name = input("Enter name of the band/artist: ")
        featured_artist = input("Enter featured artist (-1 if None): ")
        if featured_artist == "-1":
            featured_artist = None
        album_title_id_songs = self._db.get_all_albums()
        headers = ["ID", "Title", "Songs No."]
        self.print_list(headers, album_title_id_songs)
        album_id = input("Enter Album ID: ")

        day = int(input("Enter day of release: "))
        month = int(input("Enter month of release: "))
        year = int(input("Enter year of release: "))
        release_date = Date(year, month, day)

        duration = input("Enter Song Duration: ")
        lyrics = input("Enter Song lyrics: ")

        print("Enter all Genres of the song: ")
        songs_genres = input().split(' ')

        # TODO: add list of genres to addSong
        self._db.add_song(songs_genres, url, album_id, band_name,
                          featured_artist, name, release_date, lyrics,
                          duration)
コード例 #3
0
ファイル: artist_page.py プロジェクト: RehamEzzat/Musicly
 def add_artist(self):
     name = input("Enter name: ")
     day = int(input("Enter day of birth: "))
     month = int(input("Enter month of birth: "))
     year = int(input("Enter year of birth: "))
     date = Date(year, month, day)
     artist = Artist(name, date)
     self._db.add_artist(artist)
コード例 #4
0
ファイル: views.py プロジェクト: reddysatish/satish
def desc(request,id):
    startD='1991-01-01'
    endD=Date.today()
    obj1=article.objects.get(pk=id)
    context2={'obj1' : obj1}
    obj2 = article.objects.filter( public_date__range=[startD,endD]).exclude(pk=obj1.id).order_by('?')[:4]
    context2['obj2'] = obj2

    return render(request, 'demo1/disc.html', context2)
コード例 #5
0
def validate_year(value):
    if value > timezone.now().year or value < Date(1900, 1, 1).year:
        raise ValidationError(
            '%(value)s no es un año válido. NOTA: el año debe estar entre 1900 y %(actual_year)s',
            params={
                'value': value,
                'actual_year': timezone.now().year
            },
        )
コード例 #6
0
 def __init__(self, bio, dateofbirth, gender, favcolor, *user_id):
     if not user_id:
         self.user_id = None
     else:
         self.user_id = int(user_id[0])
     self.bio = str(bio)
     dob = None
     if len(dateofbirth) > 0:
         dateparts = dateofbirth.split('/')
         dob = datetime.date(int(dateparts[2]),int(dateparts[0]),int(dateparts[1]))
     self.dateofbirth = str(Date.strftime(dob,"%m/%d/%Y"))
     self.gender = str(gender)
     self.favcolor = str(favcolor)
コード例 #7
0
 def __init__(self, user_id, title, description, current_track, track_goal, units, start, end, complete, *mission_id):
     if not mission_id:
         self.mission_id = None
     else:
         self.mission_id = int(mission_id[0])
     self.user_id = str(user_id)
     self.title = str(title)
     self.description = str(description)
     self.current_track = int(current_track)
     self.track_goal = int(track_goal)
     self.units = str(units)
     s = None
     if len(start) > 0:
         dateparts = start.split('/')
         s = datetime.date(int(dateparts[2]),int(dateparts[0]),int(dateparts[1]))
     self.start = str(Date.strftime(s,"%m/%d/%Y"))
     e = None
     if len(end) > 0:
         dateparts = end.split('/')
         e = datetime.date(int(dateparts[2]),int(dateparts[0]),int(dateparts[1]))
     self.end = str(Date.strftime(e,"%m/%d/%Y"))
     self.complete = int(complete)
コード例 #8
0
ファイル: views.py プロジェクト: reddysatish/satish
def list(request):
    startD='1991-01-01'
    endD=Date.today()

    obj = article.objects.filter( public_date__range=[startD,endD]).order_by('public_date')
#for random articles:-
    ran_art=random.choice(obj)
    obj1 = article.objects.filter( public_date__range=[startD,endD]).exclude(pk=ran_art.id).order_by('public_date')[:4]
     #for footer:

    obj2=article.objects.filter(public_date__range=[startD,endD]).order_by('?')[:4]
    context={'obj1':obj1}
    context['ran_art']=ran_art
    day = ran_art.public_date.strftime("%A")
    context['day'] = day
    context['obj2']=obj2
    return render(request, 'demo1/list.html', context)
コード例 #9
0
 def __init__(self, first_name, last_name, datejoined, email, username, password, *user_id):
     if not user_id:
         self.user_id = None
     else:
         self.user_id = int(user_id[0])
     self.first_name = str(first_name)
     self.last_name = str(last_name)
     dj = None
     if len(datejoined) > 0:
         dateparts = datejoined.split('/')
         dj = datetime.date(int(dateparts[2]),int(dateparts[0]),int(dateparts[1]))
     self.datejoined = str(Date.strftime(dj,"%m/%d/%Y"))
     self.email = str(email)
     self.username = str(username)
     self.password= str(password)
     
     
コード例 #10
0
ファイル: views.py プロジェクト: nelsonsequiera/gale
def page(request, id_num):
    startdate = '1970-01-01'
    enddate = Date.today()
    
    # gets the article based on the id recieved
    article = Article.objects.get(id = id_num)
    
    # gets the day of the article published
    day = article.pub_date.strftime("%A")
    
    # retrieves 4 articles from the db in random order
    random_four = Article.objects.filter(pub_date__range = [startdate, enddate]).order_by('?')[:4]
   
    # adding contents to the dictionary
    context_dict = {}
    context_dict['random_four'] = random_four
    context_dict['article'] = article
    context_dict['day'] = day
     
    return render(request, 'ver1/page.html', context_dict)
コード例 #11
0
def add_reuters_to_db():

    url_list = []
    reuters_urls = ['http://uk.reuters.com/tools/rss', 'http://www.reuters.com/tools/rss']

    for url in reuters_urls:

        doc = request.urlopen(url)

        soup = BeautifulSoup(doc)

        for s in soup.find_all('td', 'feedUrl'):
            m = re.search('(?<=//)(.*)', s.text)
            url_list.append("http://" + m.groups()[0])

        for u in url_list:
            print(u)
            f = feedparser.parse(u)
            if not f.feed.updated_parsed.tm_year < Date.today().year:

                fr = FeedRec(feed_url=u, feed_title=f.feed.title)
                fr.save()
コード例 #12
0
def add_reuters_to_db():

    url_list = []
    reuters_urls = [
        'http://uk.reuters.com/tools/rss', 'http://www.reuters.com/tools/rss'
    ]

    for url in reuters_urls:

        doc = request.urlopen(url)

        soup = BeautifulSoup(doc)

        for s in soup.find_all('td', 'feedUrl'):
            m = re.search('(?<=//)(.*)', s.text)
            url_list.append("http://" + m.groups()[0])

        for u in url_list:
            print(u)
            f = feedparser.parse(u)
            if not f.feed.updated_parsed.tm_year < Date.today().year:

                fr = FeedRec(feed_url=u, feed_title=f.feed.title)
                fr.save()
コード例 #13
0
from sqlite3 import Date


class User:
    def __init__(self, birthday):
        self.__birthday = birthday

    def get_age(self):
        return 2018 - self.__birthday.year


if __name__ == '__main__':
    user = User(Date(1990, 2, 1))
    # 双下划线的私有属性,是不能直接访问的,只能通过类里面的公共的方法访问
    # print(user.birthday)
    # print(user._User__birthday)   #可以通过这个来访问私有属性
    print(user.get_age())