/etc/bpython-settings.py

https://bitbucket.org/alexanderbohn/tessar · Python · 80 lines · 48 code · 20 blank · 12 comment · 4 complexity · cf273f100bc4bcea649cc3b1bae388f8 MD5 · raw file

  1. from __future__ import print_function
  2. ## timer
  3. import time
  4. t1 = time.time()
  5. import os
  6. os.environ['DJANGO_SETTINGS_MODULE'] = 'tessar.settings'
  7. from django.conf import settings
  8. #from django.contrib.auth.models import User
  9. #fish = User.objects.get(username='fish')
  10. # numpy/scipy ndimages
  11. import numpy
  12. from imread import imread
  13. #from scipy import ndimage
  14. #import skimage
  15. #import skimage.filter
  16. from PIL import Image
  17. # testing images
  18. import re
  19. import random
  20. from os.path import expanduser
  21. from os import listdir
  22. #img_name = '8411181216_b16bf74632_o.jpg'
  23. impth = "~/Downloads/%s"
  24. jpre = re.compile(r"\.jpe?g$", re.IGNORECASE)
  25. TEST_IMAGES = []
  26. IMG = None
  27. def get_test_images():
  28. global jpre
  29. global impth
  30. global TEST_IMAGES
  31. TEST_IMAGES.extend(
  32. map(lambda imfile: expanduser(impth % imfile),
  33. filter(lambda imfile: jpre.search(imfile),
  34. listdir(expanduser(impth % '')))))
  35. if len(TEST_IMAGES) > 0:
  36. print(">>> Populated TEST_IMAGES with %d JPEGs (from %s)" % (
  37. len(TEST_IMAGES),
  38. expanduser(impth % "")))
  39. def get_random_image():
  40. global IMG
  41. if not len(TEST_IMAGES) > 0:
  42. return None
  43. IMG = imread(random.choice(TEST_IMAGES))
  44. get_test_images()
  45. get_random_image()
  46. ## web scraping stuff
  47. from bs4 import BeautifulSoup
  48. ## misc stuff
  49. import os, sys, requests, xerox, shutil
  50. from os.path import expanduser, basename, dirname, join
  51. import fullcontact
  52. try:
  53. fc = fullcontact.FullContact(os.environ['FULLCONTACT_API_KEY'])
  54. except TypeError:
  55. print("--- ERROR: FullContact wrapper failed to initialize")
  56. ## how long... has this been... going on?
  57. t2 = time.time()
  58. dt = str((t2-t1)*1.00)
  59. dtout = dt[:(dt.find(".")+4)]
  60. print(">>> VirtualEnv TESSAR Praxon loaded in %ssec from %s" % (dtout, '/Users/fish/Praxa/TESSAR'))