1. Python / Говнокод #22391

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    #!/usr/bin/python
    
    # encoding utf8
    # head1 NAME
    #
    # stripe_account_balance
    #
    # CONFIGURATION
    #
    # This script is used to generate the daily totals for events that stripe has
    # fired within the current day.  At the time of writing the following events
    # are supported (see: https://stripe.com/docs/api#event_types)
    #
    # account.updated, account.application.deauthorized, balance.available, 
    # charge.succeeded, charge.failed, charge.refunded, charge.captured, 
    # charge.dispute.created, charge.dispute.updated, charge.dispute.closed, 
    # customer.created, customer.updated, customer.deleted, customer.card.created, 
    # customer.card.updated, customer.card.deleted, customer.subscription.created, 
    # customer.subscription.updated, customer.subscription.deleted, 
    # customer.subscription.trial_will_end, customer.discount.created, 
    # customer.discount.updated, customer.discount.deleted, invoice.created, 
    # invoice.updated, invoice.payment_succeeded, invoice.payment_failed, 
    # invoiceitem.created, invoiceitem.updated, invoiceitem.deleted, plan.created, 
    # plan.updated, plan.deleted, coupon.created, coupon.deleted, transfer.created, 
    # transfer.updated, transfer.paid, transfer.failed, ping, 
    # 
    # APPLICABLE SYSTEMS
    #
    # Any
    #
    # CONFIGURATION
    #
    # you will need to have the following configuration items
    #  env.STRIPE_API_KEY_PROD
    #
    
    import sys, os, string, urllib2, stripe
    from urllib2 import HTTPError
    from datetime import datetime
    import time
    import socket
    
    THIS_SCRIPT_NAME ="stripe_event_counter_"
    stripe.api_key = os.environ.get("STRIPE_API_KEY_PROD")
    
    def get_stats(event_type):
    	# get the time for todays 00:00
    	now = datetime.now()
    	previous_midnight = datetime(now.year, now.month, now.day)
    	previous_midnight_timestamp = int(time.mktime(previous_midnight.timetuple()))
    
    	# make the call
    	try:
    		jsonPayload = stripe.Event.all(count=0, type=event_type, created={"gt":previous_midnight_timestamp})
    		print("EVENT_COUNT.value %i" % (len(jsonPayload["data"])))
    	except HTTPError, e:
    		sys.exit()
    
    
    if __name__ == "__main__":
    	full_caller_name = sys.argv[0]
    	index_of_script = full_caller_name.find(THIS_SCRIPT_NAME)
    	event_type = sys.argv[0][len(THIS_SCRIPT_NAME) + index_of_script:]
    
    	# are we doing config/autoconfig?
    	if(len(sys.argv) > 1):
    		if (sys.argv[1]=="config"):
    			print "graph_title Event Count for '" + event_type + "'."
    			print "graph_vlabel Number of Events"
    			print "graph_category stripe"
    
    			# in green
    			print "EVENT_COUNT.label " + event_type + ""
    			print "EVENT_COUNT.colour 00cc00"
    			print "EVENT_COUNT.draw AREA"
    
    			print "graph_args --base 1000 "
    			sys.exit()
    
    	get_stats(event_type)

    Запостил: munin, 19 Февраля 2017

    Комментарии (0) RSS

    Добавить комментарий

    Ошибка компиляции комментария:
    1. Гости могут высказаться только во вторник, пятницу или субботу
    ava Я, guest, находясь в здравом уме и твердой памяти, торжественно заявляю:
    А не использовать ли нам bbcode?
    • [b]жирный[/b] — жирный
    • [i]курсив[/i] — курсив
    • [u]подчеркнутый[/u] — подчеркнутый
    • [s]перечеркнутый[/s] — перечеркнутый
    • [blink]мигающий[/blink] — мигающий
    • [color=red]цвет[/color] — цвет (подробнее)
    • [size=20]размер[/size] — размер (подробнее)
    • [code=<language>]some code[/code] (подробнее)
    Проверочный код