Python config.host() Examples

The following are 30 code examples of config.host(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module config , or try the search function .
Example #1
Source File: tinder_api.py    From Tinder with MIT License 6 votes vote down vote up
def gif_query(query, limit=3):
  try:
      url = config.host + '/giphy/search?limit=%s&query=%s' % (limit, query)
      r = requests.get(url, headers=headers)
      return r.json()
  except requests.exceptions.RequestException as e:
      print("Something went wrong. Could not get your gifs:", e)


# def see_friends():
#     try:
#         url = config.host + '/group/friends'
#         r = requests.get(url, headers=headers)
#         return r.json()['results']
#     except requests.exceptions.RequestException as e:
#         print("Something went wrong. Could not get your Facebook friends:", e) 
Example #2
Source File: models.py    From rxivist with GNU Affero General Public License v3.0 6 votes vote down vote up
def json(self):
    resp = {
      "id": self.id,
      "doi": self.doi,
      "first_posted": self.posted.strftime('%Y-%m-%d') if self.posted is not None else "",
      "biorxiv_url": self.url,
      "url":  f"{config.host}/v1/papers/{self.id}",
      "title": self.title,
      "category": self.collection,
      "abstract": self.abstract,
      "authors": [x.json() for x in self.authors],
      "ranks": self.ranks.json()
    }
    if self.pub_doi is not None:
      resp["publication"] = {
        "journal": self.publication,
        "doi": self.pub_doi
      }
    else:
      resp["publication"] = {}
    return resp 
Example #3
Source File: tinder_api_sms.py    From Tinder with MIT License 6 votes vote down vote up
def change_preferences(**kwargs):
    '''
    ex: change_preferences(age_filter_min=30, gender=0)
    kwargs: a dictionary - whose keys become separate keyword arguments and the values become values of these arguments
    age_filter_min: 18..46
    age_filter_max: 22..55
    age_filter_min <= age_filter_max - 4
    gender: 0 == seeking males, 1 == seeking females
    distance_filter: 1..100
    discoverable: true | false
    {"photo_optimizer_enabled":false}
    '''
    try:
        url = config.host + '/profile'
        r = requests.post(url, headers=headers, data=json.dumps(kwargs))
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not change your preferences:", e) 
Example #4
Source File: tinder_api.py    From Tinder with MIT License 6 votes vote down vote up
def get_auth_token(fb_auth_token, fb_user_id):
    if "error" in fb_auth_token:
        return {"error": "could not retrieve fb_auth_token"}
    if "error" in fb_user_id:
        return {"error": "could not retrieve fb_user_id"}
    url = config.host + '/v2/auth/login/facebook'
    req = requests.post(url,
                        headers=headers,
                        data=json.dumps(
                            {'token': fb_auth_token, 'facebook_id': fb_user_id})
                        )
    try:
        tinder_auth_token = req.json()["data"]["api_token"]
        headers.update({"X-Auth-Token": tinder_auth_token})
        get_headers.update({"X-Auth-Token": tinder_auth_token})
        print("You have been successfully authorized!")
        return tinder_auth_token
    except Exception as e:
        print(e)
        return {"error": "Something went wrong. Sorry, but we could not authorize you."} 
Example #5
Source File: tinder_api.py    From Tinder with MIT License 6 votes vote down vote up
def change_preferences(**kwargs):
    '''
    ex: change_preferences(age_filter_min=30, gender=0)
    kwargs: a dictionary - whose keys become separate keyword arguments and the values become values of these arguments
    age_filter_min: 18..46
    age_filter_max: 22..55
    age_filter_min <= age_filter_max - 4
    gender: 0 == seeking males, 1 == seeking females
    distance_filter: 1..100
    discoverable: true | false
    {"photo_optimizer_enabled":false}
    '''
    try:
        url = config.host + '/profile'
        r = requests.post(url, headers=headers, data=json.dumps(kwargs))
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not change your preferences:", e) 
Example #6
Source File: tinder_api_sms.py    From Tinder with MIT License 5 votes vote down vote up
def dislike(person_id):
    try:
        url = config.host + '/pass/%s' % person_id
        r = requests.get(url, headers=headers)
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not dislike:", e) 
Example #7
Source File: tinder_api.py    From Tinder with MIT License 5 votes vote down vote up
def trending_gifs(limit=3):
  try:
      url = config.host + '/giphy/trending?limit=%s' % limit
      r = requests.get(url, headers=headers)
      return r.json()
  except requests.exceptions.RequestException as e:
      print("Something went wrong. Could not get the trending gifs:", e) 
Example #8
Source File: tinder_api_sms.py    From Tinder with MIT License 5 votes vote down vote up
def get_self():
    '''
    Returns your own profile data
    '''
    try:
        url = config.host + '/profile'
        r = requests.get(url, headers=headers)
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not get your data:", e) 
Example #9
Source File: tinder_api_sms.py    From Tinder with MIT License 5 votes vote down vote up
def get_meta():
    '''
    Returns meta data on yourself. Including the following keys:
    ['globals', 'client_resources', 'versions', 'purchases',
    'status', 'groups', 'products', 'rating', 'tutorials',
    'travel', 'notifications', 'user']
    '''
    try:
        url = config.host + '/meta'
        r = requests.get(url, headers=headers)
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not get your metadata:", e) 
Example #10
Source File: tinder_api_sms.py    From Tinder with MIT License 5 votes vote down vote up
def update_location(lat, lon):
    '''
    Updates your location to the given float inputs
    Note: Requires a passport / Tinder Plus
    '''
    try:
        url = config.host + '/passport/user/travel'
        r = requests.post(url, headers=headers, data=json.dumps({"lat": lat, "lon": lon}))
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not update your location:", e) 
Example #11
Source File: tinder_api_sms.py    From Tinder with MIT License 5 votes vote down vote up
def reset_real_location():
    try:
        url = config.host + '/passport/user/reset'
        r = requests.post(url, headers=headers)
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not update your location:", e) 
Example #12
Source File: tinder_api_sms.py    From Tinder with MIT License 5 votes vote down vote up
def set_webprofileusername(username):
    '''
    Sets the username for the webprofile: https://www.gotinder.com/@YOURUSERNAME
    '''
    try:
        url = config.host + '/profile/username'
        r = requests.put(url, headers=headers,
                         data=json.dumps({"username": username}))
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not set webprofile username:", e) 
Example #13
Source File: tinder_api_sms.py    From Tinder with MIT License 5 votes vote down vote up
def reset_webprofileusername(username):
    '''
    Resets the username for the webprofile
    '''
    try:
        url = config.host + '/profile/username'
        r = requests.delete(url, headers=headers)
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not delete webprofile username:", e) 
Example #14
Source File: tinder_api_sms.py    From Tinder with MIT License 5 votes vote down vote up
def get_person(id):
    '''
    Gets a user's profile via their id
    '''
    try:
        url = config.host + '/user/%s' % id
        r = requests.get(url, headers=headers)
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not get that person:", e) 
Example #15
Source File: tinder_api_sms.py    From Tinder with MIT License 5 votes vote down vote up
def send_msg(match_id, msg):
    try:
        url = config.host + '/user/matches/%s' % match_id
        r = requests.post(url, headers=headers,
                          data=json.dumps({"message": msg}))
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not send your message:", e) 
Example #16
Source File: tinder_api_sms.py    From Tinder with MIT License 5 votes vote down vote up
def superlike(person_id):
    try:
        url = config.host + '/like/%s/super' % person_id
        r = requests.post(url, headers=headers)
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not superlike:", e) 
Example #17
Source File: tinder_api.py    From Tinder with MIT License 5 votes vote down vote up
def fast_match_info():
  try:
      url = config.host + '/v2/fast-match/preview'
      r = requests.get(url, headers=headers)
      count = r.headers['fast-match-count']
      # image is in the response but its in hex..
      return count
  except requests.exceptions.RequestException as e:
      print("Something went wrong. Could not get your fast-match count:", e) 
Example #18
Source File: tinder_api_sms.py    From Tinder with MIT License 5 votes vote down vote up
def report(person_id, cause, explanation=''):
    '''
    There are three options for cause:
        0 : Other and requires an explanation
        1 : Feels like spam and no explanation
        4 : Inappropriate Photos and no explanation
    '''
    try:
        url = config.host + '/report/%s' % person_id
        r = requests.post(url, headers=headers, data={
                          "cause": cause, "text": explanation})
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not report:", e) 
Example #19
Source File: tinder_api_sms.py    From Tinder with MIT License 5 votes vote down vote up
def match_info(match_id):
    try:
        url = config.host + '/matches/%s' % match_id
        r = requests.get(url, headers=headers)
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not get your match info:", e) 
Example #20
Source File: tinder_api_sms.py    From Tinder with MIT License 5 votes vote down vote up
def all_matches():
    try:
        url = config.host + '/v2/matches'
        r = requests.get(url, headers=headers)
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not get your match info:", e)

# def see_friends():
#     try:
#         url = config.host + '/group/friends'
#         r = requests.get(url, headers=headers)
#         return r.json()['results']
#     except requests.exceptions.RequestException as e:
#         print("Something went wrong. Could not get your Facebook friends:", e) 
Example #21
Source File: main.py    From rxivist with GNU Affero General Public License v3.0 5 votes vote down vote up
def paper_details(id):
  # if the ID passed in isn't an integer, assume it's a DOI
  try:
    article_id = int(id)
  except Exception:
    print("\n\n\nNOT AN INT")
    new_id = helpers.doi_to_id(id, connection)
    print(f'New ID is {new_id}')
    if new_id:
      print(f"{config.host}/v1/papers/{new_id}")
      return bottle.redirect(f"{config.host}/v1/papers/{new_id}", 301)
    else:
      bottle.response.status = 404
      return {"error": "Could not find bioRxiv paper with that DOI"}
  try:
    paper = endpoints.paper_details(id, connection)
  except helpers.NotFoundError as e:
    bottle.response.status = 404
    return {"error": e.message}
  except ValueError as e:
    bottle.response.status = 500
    return {"error": f"Server error – {e}"}
  bottle.response.set_header("Cache-Control", f'max-age={config.cache["paper"]}, stale-while-revalidate=172800')
  return paper.json()

# paper download stats 
Example #22
Source File: models.py    From rxivist with GNU Affero General Public License v3.0 5 votes vote down vote up
def json(self):
    return {
      "id": self.id,
      "metric": self.downloads,
      "title": self.title,
      "url": f"{config.host}/v1/papers/{self.id}",
      "biorxiv_url": self.url,
      "doi": self.doi,
      "category": self.collection,
      "first_posted": self.posted.strftime('%Y-%m-%d') if self.posted is not None else "",
      "abstract": self.abstract,
      "authors": [x.json() for x in self.authors]
    } 
Example #23
Source File: models.py    From rxivist with GNU Affero General Public License v3.0 5 votes vote down vote up
def json(self):
    return {
      "id": self.id,
      "doi": self.doi,
      "biorxiv_url": self.url,
      "url": f"{config.host}/v1/papers/{self.id}",
      "title": self.title,
      "category": self.collection,
      "ranks": self.ranks.json()
    } 
Example #24
Source File: vsphere-monitor.py    From vsphere-monitor with Apache License 2.0 5 votes vote down vote up
def HostInformation(host,datacenter_name,computeResource_name,content,perf_dict,vchtime,interval):
    try:
        statInt = interval/20
        summary = host.summary
        stats = summary.quickStats
        hardware = host.hardware

        tags = "datacenter=" + datacenter_name + ",cluster_name=" + computeResource_name + ",host=" + host.name

        uptime = stats.uptime
        add_data("esxi.uptime",uptime,"GAUGE",tags)

        cpuUsage = 100 * 1000 * 1000 * float(stats.overallCpuUsage) / float(hardware.cpuInfo.numCpuCores * hardware.cpuInfo.hz)
        add_data("esxi.cpu.usage",cpuUsage,"GAUGE",tags)

        memoryCapacity = hardware.memorySize
        add_data("esxi.memory.capacity",memoryCapacity,"GAUGE",tags)

        memoryUsage = stats.overallMemoryUsage * 1024 * 1024
        add_data("esxi.memory.usage",memoryUsage,"GAUGE",tags)

        freeMemoryPercentage = 100 - (
            (float(memoryUsage) / memoryCapacity) * 100
        )
        add_data("esxi.memory.freePercent",freeMemoryPercentage,"GAUGE",tags)

        statNetworkTx = BuildQuery(content, vchtime, (perf_id(perf_dict, 'net.transmitted.average')), "", host, interval)       
        networkTx = (float(sum(statNetworkTx[0].value[0].value) * 8 * 1024) / statInt)
        add_data("esxi.net.if.out",networkTx,"GAUGE",tags)
        
        statNetworkRx = BuildQuery(content, vchtime, (perf_id(perf_dict, 'net.received.average')), "", host, interval)
        networkRx = (float(sum(statNetworkRx[0].value[0].value) * 8 * 1024) / statInt)
        add_data("esxi.net.if.in",networkRx,"GAUGE",tags)

        add_data("esxi.alive",1,"GAUGE",tags)

    except Exception as error:
        print "Unable to access information for host: ", host.name
        print error
        pass 
Example #25
Source File: vsphere-monitor.py    From vsphere-monitor with Apache License 2.0 5 votes vote down vote up
def ComputeResourceInformation(computeResource,datacenter_name,content,perf_dict,vchtime,interval):
    try:
        hostList = computeResource.host
        computeResource_name = computeResource.name
        for host in hostList:
            if (host.name in config.esxi_names) or (len(config.esxi_names) == 0):
                HostInformation(host,datacenter_name,computeResource_name,content,perf_dict,vchtime,interval)
    except Exception as error:
        print "Unable to access information for compute resource: ",
        computeResource.name
        print error
        pass 
Example #26
Source File: tinder_api.py    From Tinder with MIT License 5 votes vote down vote up
def reset_real_location():
    try:
        url = config.host + '/passport/user/reset'
        r = requests.post(url, headers=headers)
        return r.json()
    except requests.exceptions.RequestException as e:
        print("Something went wrong. Could not update your location:", e) 
Example #27
Source File: app.py    From shorty with MIT License 5 votes vote down vote up
def analytics(short_url):

	info_fetch , counter_fetch , browser_fetch , platform_fetch = list_data(short_url)
	return render_template("data.html" , host = shorty_host,info = info_fetch ,counter = counter_fetch ,\
	 browser = browser_fetch , platform = platform_fetch) 
Example #28
Source File: threataggregator.py    From threataggregator with MIT License 5 votes vote down vote up
def syslog(message):
    """ Send a UDP syslog packet

    :param string message: Sends a raw message to syslog
    :return:
    """
    level = LEVEL['info']
    facility = FACILITY['local0']

    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    # We have to encode as UTF8 for non-ascii characters.

    data = u'<%d>%s' % (level + facility * 8, message)
    s.sendto(data.encode('utf-8'),(config.host, config.port))
    s.close() 
Example #29
Source File: app.py    From shorty with MIT License 5 votes vote down vote up
def search():
	s_tag = request.form.get('search_url')
	if s_tag == "":
		return render_template('index.html', error = "Please enter a search term")
	else:
		conn = MySQLdb.connect(host , user , passwrd, db)
		cursor = conn.cursor()
		
		search_tag_sql = "SELECT * FROM WEB_URL WHERE TAG = %s" 
		cursor.execute(search_tag_sql , (s_tag, ) )
		search_tag_fetch = cursor.fetchall()
		conn.close()
		return render_template('search.html' , host = shorty_host , search_tag = s_tag , table = search_tag_fetch ) 
Example #30
Source File: display_list.py    From shorty with MIT License 5 votes vote down vote up
def list_data(shorty_url):
	
	"""
		Takes short_url for input.
		Returns counter , browser , platform ticks. 
	"""
	conn = MySQLdb.connect(host , user , passwrd, db)
	cursor = conn.cursor()
	su =[shorty_url]
	info_sql = "SELECT URL , S_URL ,TAG FROM WEB_URL WHERE S_URL= %s; "
	counter_sql = "SELECT COUNTER FROM WEB_URL WHERE S_URL= %s; "
	browser_sql = "SELECT CHROME , FIREFOX , SAFARI, OTHER_BROWSER FROM WEB_URL WHERE S_URL =%s;"
	platform_sql = "SELECT ANDROID , IOS , WINDOWS, LINUX , MAC , OTHER_PLATFORM FROM WEB_URL WHERE S_URL = %s;"	
	
	
	# MySQLdb's execute() function expects a list
	# of objects to be converted so we use [arg ,]
	# But for sqlite ( args,) works. 
	
	
	cursor.execute(info_sql , su)
	info_fetch = cursor.fetchone()
	cursor.execute(counter_sql , su)
	counter_fetch = cursor.fetchone()
	cursor.execute(browser_sql,su)
	browser_fetch = cursor.fetchone()
	cursor.execute(platform_sql, su)
	platform_fetch = cursor.fetchone()
	conn.close()
	return info_fetch , counter_fetch , browser_fetch , platform_fetch