Ejemplo n.º 1
0
def create_show_submission():
    # called to create new shows in the db, upon submitting new show listing form
    # TODO: insert form data as a new Show record in the db, instead
    form = ShowForm()
    created = False

    if form.validate_on_submit():
        try:
            new_show = Show(start_time=form.start_time.data)
            new_show.venue = form.venue.data
            new_show.artist = form.artist.data
            db.session.add(new_show)
            db.session.commit()
            # on successful db insert, flash success
            created = True
            flash("Show was successfully listed!")

        except:
            print(sys.exc_info())
        finally:
            db.session.close()

        if created:
            return redirect(url_for("index"))

    # TODO: on unsuccessful db insert, flash an error instead.
    flash("An error occurred. Show could not be listed.")
    return render_template("forms/new_show.html", form=form)
Ejemplo n.º 2
0
    def test_is_contributor_name_in_title(self):
        # create a show with some credits
        show = Show(title="The Contributor Title Show")
        show.save()
        matching_contributor = ShowContributor(title="       ConTRIbutoR Title            ")
        matching_contributor.save()
        nonmatching_contributor = ShowContributor(title="  Foo Bar   ")
        nonmatching_contributor.save()

        # ignore case and leading/trailing whitespace. match on title
        self.failUnless(show.is_contributor_title_in_title(matching_contributor))
        
        # check for failure
        self.failIf(show.is_contributor_title_in_title(nonmatching_contributor))
Ejemplo n.º 3
0
 def feed_extra_kwargs(self, obj):
     kwargs = super().feed_extra_kwargs(obj)
     kwargs['explicit'] = obj.is_include_explicit_language
     kwargs['image'] = obj.image
     kwargs['category'] = obj.category
     kwargs['subcategory'] = obj.subcategory
     kwargs['block'] = obj.is_blocked
     kwargs['complete'] = obj.is_complete
     kwargs['type'] = Show.Type(obj.type).value
     return kwargs
Ejemplo n.º 4
0
    def test_get_primary_contributors(self):
        # create website site item and set as current site
        web_site = Site(domain="web.address.com")
        web_site.save()
        settings.SITE_ID = web_site.id
        
        # create a show with some credits
        show = Show(title="title")
        show.save()
        contributor1 = ShowContributor(title="title", state="published")
        contributor1.save()
        contributor1.sites.add(web_site)
        contributor2 = ShowContributor(title="title", state="published")
        contributor2.save()
        contributor2.sites.add(web_site)
        contributor3 = ShowContributor(title="title", state="published")
        contributor3.save()
        contributor3.sites.add(web_site)
        contributor4 = ShowContributor(title="title", state="published")
        contributor4.save()
        contributor4.sites.add(web_site)
        unpublished_contributor = ShowContributor(title="title")
        unpublished_contributor.save()
        Credit(show=show, contributor=contributor1, role=2).save()
        Credit(show=show, contributor=contributor2, role=10).save()
        Credit(show=show, contributor=contributor3, role=2).save()
        Credit(show=show, contributor=unpublished_contributor, role=2).save()
        Credit(show=show, contributor=contributor4).save()

        # result should only contain contributors with highest role. 
        # can contain multiples.
        # highest role not neccessarily 1. 
        # result should not include non permitted contributors.
        # result should not include contributors with None credit role
        primary_contributors = show.get_primary_contributors()
        self.failUnless(contributor1 in primary_contributors)
        self.failUnless(contributor3 in primary_contributors)
        self.failIf(contributor2 in primary_contributors)
        self.failIf(unpublished_contributor in primary_contributors)
        self.failIf(contributor4 in primary_contributors)
Ejemplo n.º 5
0
def insert_data():
    source = requests.get(
        'https://www.imdb.com/movies-in-theaters/?ref_=nv_tp_inth_1').text
    # count = 0
    # counter = 0
    for month in range(12, 0, -1):
        # count = count + 1
        soup = BeautifulSoup(source, 'lxml')
        for article in soup.find_all('div', class_='list_item'):
            title = article.h4.a.text
            genre = []
            for item in article.p.find_all('span', class_=False):
                genre.append(item.text)
            storyline = article.find('div', class_='outline').text
            storyline = storyline.lstrip()
            Director = []
            try:
                for director in article.find_all('div', class_='txt-block'):
                    for directors in director.find_all('a'):
                        Director.append(directors.text)
            except:
                Director = None
            image = article.img['src']
            link = article.find('div', class_='image').a['href']
            titleName = title[1:len(title) - 7]
            print(titleName)
            print()
            print()

            genres = genre
            temp_genres = GENRE.objects.all()
            GENRES = []
            for genre in genres:
                key_genre = False
                for i in temp_genres:
                    if i.genres == genre:
                        key_genre = True
                if not key_genre:
                    GENRE.objects.create(genres=genre)
                    # GENRE.save()
            temp_genres = GENRE.objects.all()
            for gen in genres:
                for i in temp_genres:
                    if i.genres == gen:
                        GENRES.append(i)
            Languages = ["English"]
            LANGUAGES = []
            temp_langs = language.objects.all()
            for lang in Languages:
                key_lang = False
                # print(lang)
                for i in temp_langs:
                    if i.languages == lang:
                        key_lang = True
                if not key_lang:
                    language.objects.create(languages=lang)

            for lang in Languages:
                for i in temp_langs:
                    if i.languages == lang:
                        LANGUAGES.append(i)

            storyLine = storyline[0:len(storyline) - 20]
            Directors = Director
            DIRECTORS = []
            dirs = D.objects.all()

            for dir in Directors:
                key_director = False
                for i in dirs:
                    if i.name == dir:
                        key_director = True
                if not key_director:
                    D.objects.create(name=dir)
                    break
                break
                # D.save()
            # counter = counter+1

            imageLink = image
            titlePoster1 = link
            source2 = requests.get(f"https://www.imdb.com{link}").text
            soup2 = BeautifulSoup(source2, 'lxml')
            article2 = soup2.find('div', id='titleDetails')
            dor = soup2.find('div', class_='subtext')
            dor = dor.find_all('a')[-1]
            dor = dor.text
            temp1 = dor.find('(')
            dor = dor[0:temp1 - 1]
            h = dor.split(" ")
            if h[1] == "January":
                h[1] = "Jan"
                dor = h[0] + ' ' + h[1] + ' ' + h[2]
            if h[1] == "February":
                h[1] = "Feb"
                dor = h[0] + ' ' + h[1] + ' ' + h[2]
            if h[1] == "March":
                h[1] = "Mar"
                dor = h[0] + ' ' + h[1] + ' ' + h[2]
            if h[1] == "April":
                h[1] = "Apr"
                dor = h[0] + ' ' + h[1] + ' ' + h[2]
            if h[1] == "June":
                h[1] = "Jun"
                dor = h[0] + ' ' + h[1] + ' ' + h[2]
            if h[1] == "July":
                h[1] = "Jul"
                dor = h[0] + ' ' + h[1] + ' ' + h[2]
            if h[1] == "August":
                h[1] = "Aug"
                dor = h[0] + ' ' + h[1] + ' ' + h[2]
            if h[1] == "September":
                h[1] = "Sep"
                dor = h[0] + ' ' + h[1] + ' ' + h[2]
            if h[1] == "October":
                h[1] = "Oct"
                dor = h[0] + ' ' + h[1] + ' ' + h[2]
            if h[1] == "November":
                h[1] = "Nov"
                dor = h[0] + ' ' + h[1] + ' ' + h[2]
            if h[1] == "December":
                h[1] = "Dec"
                dor = h[0] + ' ' + h[1] + ' ' + h[2]
            date_time_obj = datetime.datetime.strptime(dor, '%d %b %Y')
            article2 = article2.find_all('div', class_='txt-block')
            languages = []
            for temp in article2[2].find_all('a'):
                languages.append(temp.text)
            Languages = languages
            LANGUAGES = []
            temp_langs = language.objects.all()
            for lang in Languages:
                key_lang = False
                # print(lang)
                for i in temp_langs:
                    if i.languages == lang:
                        key_lang = True
                if not key_lang:
                    language.objects.create(languages=lang)
                    # language.save()
            temp_langs = language.objects.all()
            for lang in Languages:
                for i in temp_langs:
                    if i.languages == lang:
                        LANGUAGES.append(i)
            print(Directors)

            temp_dirs = D.objects.all()
            for dir in range(0, len(Directors)):
                for i in temp_dirs:
                    print(dir, end="")
                    print(Directors[dir] + "----" + i.name, end=" ")
                    if i.name == Directors[dir]:
                        print("hello")
                        DIRECTORS.append(i)
                    print()
            print("GENRES", GENRES)
            print("DIRECTORS", DIRECTORS)
            print("LANGUAGES", LANGUAGES)
            bud = random.randint(500, 1500)
            bud = round(float(bud / 11), 2)
            boc = random.randint(1500, 2000)
            boc = round(float(bud / 11), 2)
            key_insert_movie = True
            for i in Show.objects.all():
                if i.titleName == titleName:
                    key_insert_movie = False
            if key_insert_movie:
                instance = Show(titleName=titleName,
                                releaseDate=date_time_obj,
                                storyLine=storyLine,
                                budget=bud,
                                suggested_count=0,
                                BoxOfficeCollection=boc,
                                imageLink=imageLink)
                instance.save()
                for i in DIRECTORS:
                    instance.director.add(i)
                for i in LANGUAGES:
                    instance.language.add(i)
                for i in GENRES:
                    instance.GENRE.add(i)

            # instance.cast.add(GENRES)
            # break
        source = requests.get(
            f"https://www.imdb.com/movies-coming-soon/2018-{month}").text
    insert_data_tvshow()