Guest User

Untitled

a guest
Nov 12th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. # Setup SQLAlchemy
  2. engine = create_engine('mysql://user:%s@localhost:3306/ghostifi' % urlquote('password@!'), echo=False)
  3. Session = sessionmaker(bind=engine)
  4. Base = declarative_base()
  5.  
  6. # DB classes
  7. class Subscription(Base):
  8. __tablename__ = 'wp_edd_subscriptions'
  9.  
  10. id = Column(Integer, primary_key=True)
  11. customer_id = Column(Integer)
  12. period = Column(String)
  13. initial_amount = Column(String)
  14. recurring_amount = Column(String)
  15. bill_times = Column(Integer)
  16. transaction_id = Column(String)
  17. parent_payment_id = Column(Integer)
  18. product_id = Column(Integer)
  19. created = Column(Date)
  20. expiration = Column(Date)
  21. trial_period = Column(String)
  22. status = Column(String)
  23. profile_id = Column(String)
  24. notes = Column(String)
  25. server = relationship("Server", uselist=False, backref="Subscription")
  26.  
  27. class Server(Base):
  28. __tablename__ = 'servers'
  29.  
  30. id = Column(Integer, primary_key=True)
  31. product_id = Column(Integer)
  32. wp_edd_sub_id = Column(Integer, ForeignKey(Subscription.id))
  33. server_ip = Column(String)
  34. server_name = Column(String)
  35. email = Column(String)
  36. root_password = Column(String)
  37. bandwidth_this_month = Column(Integer)
  38. bandwidth_limit_this_month = Column(Integer)
  39. current_location = Column(String)
  40. rebuild_schedule = Column(String)
  41. rebuild_schedule_location = Column(String)
  42. rebuild_now_status = Column(Integer)
  43. rebuild_now_location = Column(String)
  44. ovpn_file = Column(String)
  45. status = Column(String)
  46.  
  47. def __init__(self, product_id, wp_edd_sub_id, server_ip, server_name, email, root_password, ovpn_file, status, bandwidth_limit_this_month):
  48. self.product_id = product_id
  49. self.wp_edd_sub_id = wp_edd_sub_id
  50. self.server_ip = server_ip
  51. self.server_name = server_name
  52. self.email = email
  53. self.root_password = root_password
  54. self.bandwidth_this_month = 0
  55. self.current_location = "New Jersey"
  56. self.rebuild_schedule = "None"
  57. self.rebuild_now_status = 0
  58. self.rebuild_now_location = "New Jersey"
  59. self.ovpn_file = ovpn_file
  60. self.status = status
  61.  
  62. Base.metadata.create_all(engine)
  63. session = Session()
  64.  
  65. # Get all servers which have already been built
  66. servers = session.query(Server).all()
  67. for server in servers:
  68. print server.server_name
  69.  
  70. # Get all active subscriptions
  71. subscriptions = session.query(Subscription).filter(Subscription.status=="Active").all()
  72. for subscription in subscriptions:
  73. print subscription.status
Add Comment
Please, Sign In to add comment