Esempio n. 1
0
    def test_defaultheaders(self):
        unirest.default_header('custom', 'custom header')
        response = unirest.get('http://httpbin.org/get')
        self.assertEqual(response.code, 200)
        self.assertTrue('Custom' in response.body['headers'])
        self.assertEqual(response.body['headers']['Custom'], "custom header")

        # Make another request
        response = unirest.get('http://httpbin.org/get')
        self.assertEqual(response.code, 200)
        self.assertTrue('Custom' in response.body['headers'])
        self.assertTrue(response.body['headers']['Custom'], "custom header")

        # Clear the default headers
        unirest.clear_default_headers()
        response = unirest.get('http://httpbin.org/get')
        self.assertEqual(response.code, 200)
        self.assertFalse('Custom' in response.body['headers'])
Esempio n. 2
0
	def test_defaultheaders(self):
		unirest.default_header('custom','custom header')
		response = unirest.get('http://httpbin.org/get')
		self.assertEqual(response.code, 200)
		self.assertTrue('Custom' in response.body['headers']);
		self.assertEqual(response.body['headers']['Custom'], "custom header")

		# Make another request
		response = unirest.get('http://httpbin.org/get')
		self.assertEqual(response.code, 200)
		self.assertTrue('Custom' in response.body['headers']);
		self.assertTrue(response.body['headers']['Custom'], "custom header")

		# Clear the default headers
		unirest.clear_default_headers()
		response = unirest.get('http://httpbin.org/get')
		self.assertEqual(response.code, 200)
		self.assertFalse('Custom' in response.body['headers']);
Esempio n. 3
0
    def test_defaultheaders(self):
        unirest.default_header("custom", "custom header")
        response = unirest.get("http://httpbin.org/get")
        self.assertEqual(response.code, 200)
        self.assertTrue("Custom" in response.body["headers"])
        self.assertEqual(response.body["headers"]["Custom"], "custom header")

        # Make another request
        response = unirest.get("http://httpbin.org/get")
        self.assertEqual(response.code, 200)
        self.assertTrue("Custom" in response.body["headers"])
        self.assertTrue(response.body["headers"]["Custom"], "custom header")

        # Clear the default headers
        unirest.clear_default_headers()
        response = unirest.get("http://httpbin.org/get")
        self.assertEqual(response.code, 200)
        self.assertFalse("Custom" in response.body["headers"])
Esempio n. 4
0
    parser.add_argument("--cleardb", help="clear database", action="store_true")
    parser.add_argument("--debug", help="debug mode, even more verbose", action="store_true")
    parser.add_argument("--mctsmoms", help="number of MCTS mothers", type=int, default=0)
    parser.add_argument("--mctskids", help="number of MCTS children", type=int, default=0)
    parser.add_argument("--lmp", help="static LMP", action="store_true")
    parser.add_argument("--dob", help="static DOB", action="store_true")
    args = parser.parse_args()

    if args.verbose:
        print "verbose mode\nargs={}".format(args)

    #
    # http defaults
    #
    unirest.timeout(30)
    unirest.default_header("Accept", "application/json")

    #
    # Clear the database?
    #
    if args.cleardb:
        unirest.timeout(600)
        exec_http_get("{}/module/testing/clearDatabase".format(args.server))
        unirest.timeout(30)
        exec_http_get("{}/module/testing/createSubscriptionPacks".format(args.server))
        import_region_domain_data("state")
        import_region_domain_data("circleName")
        import_region_domain_data("district")
        import_domain_data("languageCode/import", "language_location_code.csv")

    #
Esempio n. 5
0
secret_key = urandom(32)

# X-Mashape-Key
api_key = "frXllSpx5amshUV29IPWvrEiIk3Tp1qJGikjsnhgwldpgnfGEO"

# Translating API Links
yoda = "https://yoda.p.mashape.com/yoda?sentence=%s"
l33t = "https://montanaflynn-l33t-sp34k.p.mashape.com/encode?text=%s"
translator = [l33t]

# Meme Generator Link
memeURL = "http://apimeme.com/meme?meme=%(mem)s&top=%(top)s&bottom=%(bottom)s"
memes = ["Grandma+Finds+The+Internet", "Condescending+Wonka", "Grumpy+Cat+Table", "Hipster+Barista"]

fillertexts = ["1'll+wReCk+y0u+m8t3", "That's+Nice,+tell+me+more", "I+hate+you", "Been+there,+done+that"]

unirest.default_header("X-Mashape-Key", api_key)


def generate(line, meme):
    if meme == 0:
        line = translate(line, meme)
    return memeURL % {"bottom": fillertexts[meme], "mem": memes[meme], "top": line}


def translate(line, meme):
    line = line.replace(" ", "+")
    print line
    stringer = unirest.get(translator[meme] % (line), headers={"Accept": "text/plain"})
    return stringer.body
Esempio n. 6
0
def set_unirest_defaults():
    unirest.default_header("X-Mashape-User", "TESTUSER")
    unirest.default_header("X-Mashape-Proxy-Secret", "DEBUG")
Esempio n. 7
0
import os, unirest

api_url_createUser        = '******'
api_url_createPost        = 'http://localhost:4567/api/CreaPost'
api_url_getUserInfo       = 'http://localhost:4567/api/getUsuario/'
api_url_getUserPosts      = 'http://localhost:4567/api/getPostsUsuario/'
api_url_getUserFollowers  = 'http://localhost:4567/api/getUsuarioFollowers'
api_url_getUserFollowing  = 'http://localhost:4567/api/getUsuarioFollowing'
api_url_getAllPublicPosts = 'http://localhost:4567/api/getPostsPublicos'

# Unirest Defaults
# ===

# Defaults that will be sent on every request
unirest.default_header('Accept','application/json')

# Requests Helpers
# ===

def makePOST(api_url, params):
	response = unirest.post(api_url, params=params)
	showResponse(response)
	showContinuePrompt()

def makeGET(api_url, params):
	response = unirest.get(api_url, params=params)
	showResponse(response)
	showContinuePrompt()

def showResponse(response):
Esempio n. 8
0
                        help="debug mode, even more verbose",
                        action="store_true")
    parser.add_argument("--mctsmoms",
                        help="number of MCTS mothers",
                        type=int,
                        default=0)
    args = parser.parse_args()

    if args.verbose:
        print "verbose mode\nargs={}".format(args)

    #
    # http defaults
    #
    unirest.timeout(30)
    unirest.default_header("Accept", "application/json")

    #
    # Clear the database?
    #
    if args.cleardb:
        unirest.timeout(600)
        exec_http_get("{}/module/testing/clearDatabase".format(args.server))
        unirest.timeout(30)
        exec_http_get("{}/module/testing/createSubscriptionPacks".format(
            args.server))
        import_region_domain_data("state")
        import_region_domain_data("circle")
        import_region_domain_data("district")
        import_domain_data("languageLocationCode/import",
                           "language_location_code.csv")
Esempio n. 9
0
#!/usr/bin/python

import shlex, subprocess
import unirest
from bs4 import BeautifulSoup

KISS_URI = "http://kissanime.com"

# Define the headers that will make us look like an iphone
unirest.default_header("User-Agent",
    "Mozilla/5.0 (iPad; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) CriOS/34.0.1847.18 Mobile/11B554a Safari/9537.53")
unirest.default_header("Accept", 
    "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
unirest.default_header("Accept-Language", "en-US,en;q=0.5")
unirest.default_header("Accept-Encoding", "gzip, deflate")
unirest.default_header("Accept-Language", "en-US,en;q=0.5")

# Get the home page of the mobile site
get_main = unirest.get(KISS_URI + "/M")

# Make a bootiful soop object
main_soup = BeautifulSoup(get_main.body)

series_map = {}

# Get all the series on the main page
for series in main_soup.find_all('article'):
    series_div = series.find('div', class_='post-content')
    series_name = series_div.find('h2').get_text()
    series_link = series_div.find('a')['href']
    series_map[series_name] = KISS_URI + series_link