Hello everyone,

I'm new. I'm Martin from Spain and in spite of working as Java programmer,
I love Python and try to develop with it and learn as much as I can.

I started using imdbPY and I was very happy with the low difficulty in
larning how to use this tool. I made quickly a script which retrieves info
from IMDb movies based on the input ID of the movie itself.

I was developing under Ubuntu and it was always working, but giving an
error, so I kept on.

The problem came when I did want to make a Windows '.exe' file for
distributing it. It seems that under Ubuntu you can execute with python
properly despite the error, but in Windows the .exe file does not continue.

The error is down here, and after it, I'm pasting my code, which is a
single '.py' file. I tried creating a 'imdbpy.cfg' at the same directory,
but it goes the same.

The error happens just at the IMDb() call, as commented in my source code.
When execued with Python under Windows the code works, but when I make the
'.exe' with pyInstaller I checked that the execution stops at that line.

I need some clue, even for researching myself and know how to make a '.exe'
that works properly.

Thanks in advance.

ERROR:

2017-11-16 00:44:46,732 WARNING [imdbpy] C:\Program Files
(x86)\Python36-32\lib\site-packages\imdb\__init__.py:165: Unable to read
configuration file; complete error: 'ConfigParserWithCase' object has no
attribute '_boolean_states'
--- Logging error ---
Traceback (most recent call last):
  File "C:\Program Files
(x86)\Python36-32\lib\site-packages\imdb\parser\http\utils.py", line 499,
in parse
    self.gather_refs(dom)
  File "C:\Program Files
(x86)\Python36-32\lib\site-packages\imdb\parser\http\utils.py", line 594,
in gather_refs
    grParser = GatherRefs(useModule=self._useModule)
AttributeError: 'DOMHTMLPlotParser' object has no attribute '_useModule'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\logging\__init__.py", line
992, in emit
    msg = self.format(record)
  File "C:\Program Files (x86)\Python36-32\lib\logging\__init__.py", line
838, in format
    return fmt.format(record)
  File "C:\Program Files (x86)\Python36-32\lib\logging\__init__.py", line
575, in format
    record.message = record.getMessage()
  File "C:\Program Files (x86)\Python36-32\lib\logging\__init__.py", line
338, in getMessage
    msg = msg % self.args
TypeError: not enough arguments for format string
Call stack:
  File "C:/Users/madtyn/PycharmProjects/telegram/api_samples/IMDb/gui.pyw",
line 26, in <module>
    root.mainloop()
  File "C:\Program Files (x86)\Python36-32\lib\tkinter\__init__.py", line
1277, in mainloop
    self.tk.mainloop(n)
  File "C:\Program Files (x86)\Python36-32\lib\tkinter\__init__.py", line
1699, in __call__
    return self.func(*args)
  File "C:/Users/madtyn/PycharmProjects/telegram/api_samples/IMDb/gui.pyw",
line 17, in getIMDbData
    text = get_data(e.get())
  File
"C:\Users\madtyn\PycharmProjects\telegram\api_samples\IMDb\sample_get_info.py",
line 33, in get_data
    movie = ia.get_movie(token)
  File "C:\Program Files
(x86)\Python36-32\lib\site-packages\imdb\__init__.py", line 392, in
get_movie
    self.update(movie, info)
  File "C:\Program Files
(x86)\Python36-32\lib\site-packages\imdb\__init__.py", line 702, in update
    ret = method(mopID)
  File "C:\Program Files
(x86)\Python36-32\lib\site-packages\imdb\parser\http\__init__.py", line
523, in get_movie_plot
    return self.mProxy.plot_parser.parse(cont, getRefs=self._getRefs)
  File "C:\Program Files
(x86)\Python36-32\lib\site-packages\imdb\parser\http\utils.py", line 502,
in parse
    self._cname, exc_info=True)
Message: '%s: unable to gather refs: %s'
Arguments: ('DOMHTMLPlotParser',)


MY CODE:

from imdb import IMDb
import requests
from bs4 import BeautifulSoup


def get_field_attr(movie, field, attr, keyErrorValue='Not available'):
    try:
        info = movie[field]
        if isinstance(movie[field], list):
            result = ', '.join([elem[attr] for elem in info])
        else:
            result = movie[field][attr]
    except KeyError:
        result = keyErrorValue
    return result


def get_data(token):
    ia = IMDb() # Here the error shows up and then keeps!!!!!
    try:
        movie = ia.get_movie(token)
    except (TypeError, AttributeError):
        pass

    if movie:
        template = """Year: {year} | Director: {director} | Producer:
{producer} | Writer: {writer} |
        Music: {music} | Cinematography: {cinematography} | Editing:
{editor} | Cast: {cast} | Genres: {genres} | Duration: {duration}"""

        fields = ['director', 'producer', 'writer', 'cinematography', 'editor']
        my_dict = {field: get_field_attr(movie, field, 'name') for
field in fields}
        my_dict['music'] = get_field_attr(movie, 'music', 'name',
keyErrorValue='No original music found')

        try:
            url = 'http://www.imdb.com/title/tt{}/?ref_=nv_sr_1'.format(token)
            html_result = requests.get(url).text
            html = BeautifulSoup(html_result, 'html.parser')
            stars = html.select('span[itemprop=actors] a span[itemprop=name]')
            my_dict['cast'] = ', '.join([star.text for star in stars])
        except:
            my_dict['cast'] = get_field_attr(movie, 'cast', 'name')

        my_dict['year'] = movie['year']
        my_dict['genres'] = ', '.join(movie['genres'])
        my_dict['duration'] = movie['runtimes'][0] + ' minutes'

        return template.format(**my_dict)


if __name__ == '__main__':
    for token in ['4225622', '0133093', '1178663']:
        print(get_data(token))
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Imdbpy-help mailing list
Imdbpy-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/imdbpy-help

Reply via email to