Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Tuesday, August 5, 2014

Script Ruby Untuk Download Form C1 KPU Pilpres 2014

Script ini digunakan untuk download form C1 Pemilu Presiden 2014 versi komplit dengan format zip. Untuk beberapa hasilnya dapat dilihat di Google Drive.

Script versi Gist: https://gist.github.com/kuntoaji/c2886b227f6cdf888cea
#!/usr/bin/env ruby
require 'open-uri'

user_agent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.16 Safari/537.36"
saved_url_list = "saved_list.txt"
accessed_urls = []

accessed_urls = File.readlines(saved_url_list) if File.exists?(saved_url_list)

# tps terbanyak 149
# source: http://kpukotacimahi.com/joomla-overview/40-berita-depan/135-kelurahan-melong-memiliki-tps-terbanyak-dikota-cimahi
# jumlah tps, bisa dimodifikasi
(1..149).each do |tps|

  # id kelurahan, bisa dimodifikasi
  (1..100_000).each do |kel_id|
    url = "http://pilpres2014.kpu.go.id/c1.php?cmd=download&tps=#{tps}&kel_id=#{kel_id}"

    # saved_url_list.txt add \n as new line
    unless accessed_urls.include?("#{url}\n")
      begin
        puts "Accessing #{url}"
        content = open(url, "User-Agent" => user_agent).read
      rescue
        puts "Retrying..."
        retry
      end

      file_name = "#{kel_id}_#{tps}.zip"
      unless File.exists?(file_name)
        if content.size > 7000
          File.open(file_name, 'w') {|f| f.write(content) }
          saved_file = File.open(saved_url_list, "a")
          saved_file.puts url
          saved_file.close
          puts "#{file_name} is successfully saved"

          sleep_in_seconds = Random.rand(10..15)
          puts "sleeping for #{sleep_in_seconds} seconds.."
          sleep sleep_in_seconds
        else
          puts "Empty"
        end
      else
        puts "#{file_name} is exist"
      end
    end
  end
end

puts "done"

Saturday, February 25, 2012

PHP - Server Variables

Description: This PHP script will show information about your server environment for PHP using $_SERVER variable.

Sunday, September 11, 2011

Python - Count Feedburner's Subscriber

Summary: Python script to count subsriber from Feedburner. Before run this script, Feedburner awareness API must be activated. This is script is inspired by Eric Wendelin.
#!/usr/bin/env python

# kuntoaji.blogspot.com

# IMPORTANT: Feedburner awareness API must be activated

# Replace with your own name
feedburner_name = "railsmine"

import urllib
from xml.dom import minidom

try:
  dom = minidom.parse(urllib.urlopen('https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri='+feedburner_name))
  entry = dom.getElementsByTagName('entry')[0]
  count = entry.getAttribute('circulation')
  print "total subscriber:",count
except:
  print "Oops! Something went wrong. Check your feedburner's name or your internet connection."

PHP - Redirect Malicious IP Address

<?php 
/**
http://kuntoaji.blogspot.com
*/

/* Replace this with your IP address.. */
$malicious_ip = '127.0.0.1'

if ($_SERVER['REMOTE_ADDR'] == $malicious_ip) {
header("Location: http://www.example.com/");
}
?>

Artikel Terkait

Click Counter with jQuery

Summary: Count every user click "click me!" link

<html>
  <head>
    <title>Click Counter</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script type="text/javascript">
      // http://kuntoaji.blogspot.com
      $(function(){
          var total_click = 0;
          $("#clickMe").click(function(){
            total_click = total_click + 1;
            $("#counter").text("Total Click: " + total_click);
return false;
          });
        });
    </script>
  </head>
  <body>
    <div id="counter">Total Click: 0</div><br />
    <a id="clickMe" href="#">click me!</a>
  </body>
</html>