import win32com.client # Open PowerPoint Application = win32com.client.Dispatch("PowerPoint.Application") # Add a presentation Presentation = Application.Presentations.Add() # Add a slide with a blank layout (12 stands for blank layout) Base = Presentation.Slides.Add(1, 12) # Add an oval. Shape 9 is an oval. oval = Base.Shapes.AddShape(9, 100, 100, 100, 100) # Open Excel Application = win32com.client.Dispatch("Excel.Application") # Show Excel. Unlike PPT, Word & Excel open up "hidden" Application.Visible = 1 # Add a workbook Workbook = Application.Workbooks.Add() # Take the active sheet Base = Workbook.ActiveSheet # Add an oval. Shape 9 is an oval. oval = Base.Shapes.AddShape(9, 100, 100, 100, 100) # In the first row, add Values: 0.0, 0.5, 1.0 Base.Cells(1, 1).Value = 'Values' Base.Cells(1, 2).Value = 0.0 Base.Cells(1, 3).Value = 0.5 Base.Cells(1, 4).Value = 1.0 from lxml.html import parse tree = parse('http://www.imdb.com/chart/top') movies = tree.findall('.//table[@class="chart"]//td[@class="titleColumn"]//a') movies[0].text_content() from MSO import * Base = Presentation.Slides.Add(1, ppLayoutBlank) width, height = 28, 41 for i, movie in enumerate(movies): x = 10 + width * (i % 25) y = 100 + height * (i // 25) r = Base.Shapes.AddShape( msoShapeRectangle, x, y, width, height) import os from urlparse import urljoin from urllib import urlretrieve from hashlib import md5 # We'll keep the files under an img/ folder if not os.path.exists('img'): os.makedirs('img') def filename(movie): '''Filename = MD5 hash of its title in UTF8''' name = md5(movie.text_content().encode('utf8')).hexdigest() return os.path.join('img', name + '.jpg') for movie in movies: if os.path.exists(filename(movie)): continue url = urljoin('http://www.imdb.com/', movie.get('href')) tree = parse(url) img = tree.find('.//td[@id="img_primary"]//img') urlretrieve(img.get('src'), filename(movie)) Base = Presentation.Slides.Add(1, ppLayoutBlank) width, height = 28, 41 for i, movie in enumerate(movies): x = 10 + width * (i % 25) y = 100 + height * (i // 25) image = Base.Shapes.AddPicture( os.path.abspath(filename(movie)), LinkToFile=True, SaveWithDocument=False, Left=x, Top=y, Width=width, Height=height) Base = Presentation.Slides.Add(1, ppLayoutBlank) width, height = 28, 41 for i, movie in enumerate(movies): x = 10 + width * (i % 25) y = 100 + height * (i // 25) image = Base.Shapes.AddPicture( os.path.abspath(filename(movie)), LinkToFile=True, SaveWithDocument=False, Left=x, Top=y, Width=width, Height=height) url = urljoin('http://www.imdb.com/', movie.get('href')) link = image.ActionSettings(ppMouseClick).Hyperlink link.Address = url link.ScreenTip = movie.text_content().encode('cp1252') Base = Presentation.Slides.Add(1, ppLayoutBlank) # Add two buttons: alphabetical and by rating button_alpha = Base.Shapes.AddShape(msoShapeRectangle, 400, 10, 150, 40) button_alpha.TextFrame.TextRange.Text = 'Alphabetical' button_rating = Base.Shapes.AddShape(msoShapeRectangle, 560, 10, 150, 40) button_rating.TextFrame.TextRange.Text = 'By rating' # Get the index position when sorted alphabetically movies_alpha = sorted(movies, key=lambda v: v.text_content()) index_alpha = dict((movie.text_content(), i) for i, movie in enumerate(movies_alpha)) def animate(seq, image, trigger, path, duration=1.5): '''Move image along path when trigger is clicked''' effect = seq.AddEffect( Shape=image, effectId=msoAnimEffectPathDown, trigger=msoAnimTriggerOnShapeClick, ) ani = effect.Behaviors.Add(msoAnimTypeMotion) ani.MotionEffect.Path = path effect.Timing.TriggerType = msoAnimTriggerWithPrevious effect.Timing.TriggerShape = trigger effect.Timing.Duration = duration seq_alpha = Base.TimeLine.InteractiveSequences.Add() seq_rating = Base.TimeLine.InteractiveSequences.Add() width, height = 28, 41 for i, movie in enumerate(movies): x = 10 + width * (i % 25) y = 100 + height * (i // 25) image = Base.Shapes.AddPicture( os.path.abspath(filename(movie)), LinkToFile=True, SaveWithDocument=False, Left=x, Top=y, Width=width, Height=height) url = urljoin('http://www.imdb.com/', movie.get('href')) link = image.ActionSettings(ppMouseClick).Hyperlink link.Address = url link.ScreenTip = movie.text_content().encode('cp1252') # Alphabetical index = index_alpha[movie.text_content()] animate(seq_alpha, image, trigger=button_alpha, path='M0,0 L{:.3f},{:.3f}'.format( (10 + width * (index % 25) - x) / 720., (100 + height * (index // 25) - y) / 540., )) # By rating animate(seq_rating, image, trigger=button_rating, path='M{:.3f},{:.3f} L0,0'.format( (10 + width * (index % 25) - x) / 720., (100 + height * (index // 25) - y) / 540., )) from TwitterAPI import TwitterAPI # I'm keeping my keys and secrets in a secret file. from secret_twitter import consumer_key, consumer_secret, access_token_key, access_token_secret api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret) def draw_tweet(Base, item, pos): y = 40 + (pos % 4) * 120 image = Base.Shapes.AddPicture( # To get the larger resolution image, just remove _normal from the URL item['user']['profile_image_url'].replace('_normal', ''), LinkToFile=True, SaveWithDocument=False, Left=20, Top=y, Width=100, Height=100) try: status = item['text'].encode('cp1252') except UnicodeEncodeError: status = item['text'] text = Base.Shapes.AddShape(msoShapeRectangle, 130, y, 460, 100) text.Fill.ForeColor.ObjectThemeColor = msoThemeColorText1 text.Fill.ForeColor.Brightness = +0.95 text.Line.Visible = msoFalse text.TextFrame.TextRange.Text = status text.TextFrame.TextRange.Font.Color.ObjectThemeColor = msoThemeColorText1 text.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignLeft user = Base.Shapes.AddShape(msoShapeRectangle, 600, y, 100, 100) user.Fill.ForeColor.ObjectThemeColor = msoThemeColorAccent6 user.Line.Visible = False user.TextFrame.TextRange.Text = '@' + item['user']['screen_name'] Base = Presentation.Slides.Add(1, ppLayoutBlank) api.request('statuses/filter', {'track': 'beer'}) for pos, item in enumerate(api.get_iterator()): draw_tweet(Base, item, pos) if pos > 10: break