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

    −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
    81. 81
    82. 82
    83. 83
    84. 84
    #!/usr/bin/python
    
    # encoding utf8
    # head1 NAME
    #
    # wordpress_plugin_ - Munin plugin to display wordpress download stats for plugins.
    #
    # CONFIGURATION
    #
    # This script is used to generate data for the number of downloads of plugins
    #
    # APPLICABLE SYSTEMS
    #
    # Any system that can connect to wordpress plugins
    #
    # CONFIGURATION
    #
    # This script is used to generate data for several graphs. To generate data for
    # one specific wordpress plugin instance, you need to create a symbolic link
    # with a name like wordpress_plugin_download_counter_<NAME> to this script.
    #
    # For example: to track the WP Super Cache number of downloads
    #
    #   The URL for it is http://wordpress.org/plugins/wp-super-cache/
    #   So you would use the following --------------> ^^^^^^^^^^^^^^
    #   wp-super-cache as the name
    #
    # i.e. 
    #
    #   cd /etc/munin/plugins
    #   ln -s /usr/share/munin/plugins/wordpress_plugin_download_counter_ wordpress_plugin_download_counter_wp-super-cache
    #   /etc/init.d/munin-node restart
    #
    
    import sys, os, string, urllib2
    from urllib2 import HTTPError
    import socket
    
    THIS_SCRIPT_NAME = "wordpress_plugin_download_counter_"
    THIS_TO_BE_FOUND = "UserDownloads"
    
    def get_stats(stat_url):
    	contents=""
    	try:
    		socket.setdefaulttimeout(10)
    		response = urllib2.urlopen(stat_url)
    		contents = response.read()
    	except HTTPError, e:
    		sys.exit()
    
    	start_index_of_download = string.find(contents, THIS_TO_BE_FOUND) + len(THIS_TO_BE_FOUND) + 1
    	end_index_of_download = string.find(contents, "\"", start_index_of_download)
    
    	print("DOWNLOADS.value " + (contents[start_index_of_download: end_index_of_download]))
    
    if __name__ == "__main__":
    	# figure out which one we are doing
    	full_caller_name = sys.argv[0]
    	index_of_wordpress = full_caller_name.find(THIS_SCRIPT_NAME)
    	caller = sys.argv[0][len(THIS_SCRIPT_NAME) + index_of_wordpress:]
    	caller_nice_name = caller.replace("_", " ")
    	caller_nice_name = caller_nice_name.replace("-", " ")
    
    	# are we doing config/autoconfig?
    	if(len(sys.argv) > 1):
    		if (sys.argv[1]=="config"):
    			print "graph_title Plugin Downloads for '" + caller_nice_name.title() + "'"
    			print "graph_vlabel Number Of Downloads"
    			print "graph_category wordpress"
    			print "graph_order DOWNLOADS"
    
    			# in green
    			print "DOWNLOADS.label Downloads"
    			print "DOWNLOADS.colour 00cc00"
    			print "DOWNLOADS.draw AREA"
    
    			print "graph_args --base 1000 -l 0 "
    			print "graph_scale no "
    			sys.exit()
    
    	# now that we know the caller, get the environment
    	stat_url = "http://wordpress.org/extend/plugins/" + caller_nice_name + "/"
    	if(None != stat_url):
    		get_stats(stat_url)

    Запостил: 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] (подробнее)
    Проверочный код