-1

I have a working app using the imgur API with python.

from imgurpython import ImgurClient

client_id = '5b786edf274c63c'
client_secret = 'e44e529f76cb43769d7dc15eb47d45fc3836ff2f'

client = ImgurClient(client_id, client_secret)

items = client.subreddit_gallery('rarepuppers')
for item in items:
    print(item.link)

It outputs a set of imgur links. I want to display all those pictures on a webpage.

Does anyone know how I can integrate python to do that in an HTML page?

andreas
  • 16,357
  • 12
  • 72
  • 76
Shreyas
  • 3
  • 1
  • 3
  • Modify your program so it outputs the source to a complete HTML page instead of just some standalone links, save the output to a file, then open that file in a browser. – John Gordon Sep 16 '16 at 19:21
  • If that's not a sanitised client secret, you may want to change it on the server ASAP. – JasonD Sep 16 '16 at 19:28
  • Please accept my answer if it solved your problem, alternately please add your own solution so that others with similar problems can benefit from your experience. – JasonD Sep 19 '16 at 18:16

1 Answers1

0

OK, I haven't tested this, but it should work. The HTML is really basic (but you never mentioned anything about formatting) so give this a shot:

from imgurpython import ImgurClient

client_id = '5b786edf274c63c'
client_secret = 'e44e529f76cb43769d7dc15eb47d45fc3836ff2f'

client = ImgurClient(client_id, client_secret)

items = client.subreddit_gallery('rarepuppers')

htmloutput = open('somename.html', 'w')
htmloutput.write("[html headers here]")
htmloutput.write("<body>")

for item in items:
    print(item.link)

    htmloutput.write('<a href="' + item.link + '">SOME DESCRIPTION</a><br>')

htmloutput.write("</body</html>")
htmloutput.close

You can remove the print(item.link) statement in the code above - it's there to give you some comfort that stuff is happening.

I've made a few assumptions:

  1. The item.link returns a string with only the unformatted link. If it's already in html format, then remove the HTML around item.link in the example above.
  2. You know how to add an HTML header. Let me know if you do not.
  3. This script will create the html file in the folder it's run from. This is probably not the greatest of ideas. So adjust the path of the created file appropriately.

Once again, though, if that is a real client secret, you probably want to change it ASAP.

JasonD
  • 114
  • 6