<commit_before>#! /usr/bin/env python
# *-* coding: utf-8 *-*

import requests
import urllib
import ConfigParser

NEIS_BASEURL = 'http://resultmaps.neis-one.org/ooocs.php'


def names_in(minlon, minlat, maxlon, maxlat):
    params = {
        'ntype': 'activity',
        'bbox': '{minlon},{minlat},{maxlon},{maxlat}'.format(
            minlon=minlon,
            minlat=minlat,
            maxlon=maxlon,
            maxlat=maxlat
          )
    }

    res = requests.get(NEIS_BASEURL, params=params)

    if not res.ok:
        res.raise_for_status()

    features = res.json()['features']

    for f in features:
        yield f['properties']['n']

MAX_ZOOM_LATUNIT = 0.023481163
MAX_ZOOM_LONUNIT = 0.064373016


def grid(minlon, minlat, maxlon, maxlat):
    lon = minlon
    lat = minlat

    while lat < maxlat:
        while lon < maxlon:
            yield (lon, lat, lon + MAX_ZOOM_LONUNIT, lat + MAX_ZOOM_LATUNIT)
            lon = lon + MAX_ZOOM_LONUNIT
        lon = minlon
        lat = lat + MAX_ZOOM_LATUNIT


def names_within(minlon, minlat, maxlon, maxlat):
    for box in grid(minlon, minlat, maxlon, maxlat):
        for name in names_in(*box):
            yield name


class MessageSender(object):

    def __init__(self,
                 authenticity_token,
                 username,
                 location,
                 osm_session,
                 pk_id):
        self.authenticity_token = authenticity_token
        self.username = username
        self.location = location
        self.osm_session = osm_session
        self.pk_id = pk_id

    def send_message(self, user, subject, text):
        url = 'http://www.openstreetmap.org/message/new/{user}'.format(
                user=user
               )

        payload = {
            'utf8': urllib.unquote_plus('%E2%9C%93'),
            'authenticity_token': self.authenticity_token,
            'message[title]': urllib.unquote_plus(subject),
            'message[body]': urllib.unquote_plus(text),
            'commit': 'Send'
        }

        headers = {
            'Origin': 'http://www.openstreetmap.org',
            'Accept-Encoding': 'gzip,deflate,sdch',
            'Host': 'www.openstreetmap.org',
            'Accept-Language': 'it-IT,it;',
            'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) '
                          'AppleWebKit/537.36 (KHTML, like Gecko) '
                          'Ubuntu Chromium/30.0.1599.114 '
                          'Chrome/30.0.1599.114 Safari/537.36',
            'Content-Type': 'application/x-www-form-urlencoded',
            'Accept': 'text/html,application/xhtml+xml,application/xml;'
                      'q=0.9,image/webp,*/*;q=0.8',
            'Referer': 'http://www.openstreetmap.org/message/new/{username}',
            'Cookie': '_osm_username={username}; '
                      '_osm_location={location}; '
                      '_pk_ref.1.cf09=%5B%22%22%2C%22%22%2C1383685750%2C%22'
                      'http%3A%2F%2Fwiki.openstreetmap.org%2Fwiki%2F'
                      'OpenStreetMap_License%22%5D; '
                      '_osm_session={session}; '
                      '_pk_id.1.cf09={pk_id} '
                      '_pk_ses.1.cf09=*'.format(
                        username=self.username,
                        location=self.location,
                        session=self.osm_session,
                        pk_id=self.pk_id
                      ),
            'Connection': 'keep-alive'
        }

        requests.post(url, data=payload, headers=headers)

if __name__ == '__main__':

    # get a grid of boxes (minlon, minlat, maxlon, maxlat) in a given area
    # bounding box
    print<commit_msg>Change User-Agent in request<commit_after>#! /usr/bin/env python
# *-* coding: utf-8 *-*

import requests
import urllib
import ConfigParser

NEIS_BASEURL = 'http://resultmaps.neis-one.org/ooocs.php'


def names_in(minlon, minlat, maxlon, maxlat):
    params = {
        'ntype': 'activity',
        'bbox': '{minlon},{minlat},{maxlon},{maxlat}'.format(
            minlon=minlon,
            minlat=minlat,
            maxlon=maxlon,
            maxlat=maxlat
          )
    }

    res = requests.get(NEIS_BASEURL, params=params)

    if not res.ok:
        res.raise_for_status()

    features = res.json()['features']

    for f in features:
        yield f['properties']['n']

MAX_ZOOM_LATUNIT = 0.023481163
MAX_ZOOM_LONUNIT = 0.064373016


def grid(minlon, minlat, maxlon, maxlat):
    lon = minlon
    lat = minlat

    while lat < maxlat:
        while lon < maxlon:
            yield (lon, lat, lon + MAX_ZOOM_LONUNIT, lat + MAX_ZOOM_LATUNIT)
            lon = lon + MAX_ZOOM_LONUNIT
        lon = minlon
        lat = lat + MAX_ZOOM_LATUNIT


def names_within(minlon, minlat, maxlon, maxlat):
    for box in grid(minlon, minlat, maxlon, maxlat):
        for name in names_in(*box):
            yield name


class MessageSender(object):

    def __init__(self,
                 authenticity_token,
                 username,
                 location,
                 osm_session,
                 pk_id):
        self.authenticity_token = authenticity_token
        self.username = username
        self.location = location
        self.osm_session = osm_session
        self.pk_id = pk_id

    def send_message(self, user, subject, text):
        url = 'http://www.openstreetmap.org/message/new/{user}'.format(
                user=user
               )

        payload = {
            'utf8': urllib.unquote_plus('%E2%9C%93'),
            'authenticity_token': self.authenticity_token,
            'message[title]': urllib.unquote_plus(subject),
            'message[body]': urllib.unquote_plus(text),
            'commit': 'Send'
        }

        headers = {
            'Origin': 'http://www.openstreetmap.org',
            'Accept-Encoding': 'gzip,deflate,sdch',
            'Host': 'www.openstreetmap.org',
            'Accept-Language': 'it-IT,it;',
            'User-Agent': 'contactmap',
            'Content-Type': 'application/x-www-form-urlencoded',
            'Accept': 'text/html,application/xhtml+xml,application/xml;'
                      'q=0.9,image/webp,*/*;q=0.8',
            'Referer': 'http://www.openstreetmap.org/message/new/{username}',
            'Cookie': '_osm_username={username}; '
                      '_osm_location={location}; '
                      '_pk_ref.1.cf09=%5B%22%22%2C%22%22%2C1383685750%2C%22'
                      'http%3A%2F%2Fwiki.openstreetmap.org%2Fwiki%2F'
                      'OpenStreetMap_License%22%5D; '
                      '_osm_session={session}; '
                      '_pk_id.1.cf09={pk_id} '
                      '_pk_ses.1.cf09=*'.format(
                        username=self.username,
                        location=self.location,
                        session=self.osm_session,
                        pk_id=self.pk_id
                      ),
            'Connection': 'keep-alive'
        }

        requests.post(url, data=payload, headers=headers)

if __name__ == '__main__':

    # get a grid of boxes (minlon, minlat, maxlon, maxlat) in a given area
    # bounding box
    print
{'fraction_non_alphanumeric': 0.1242835174052845, 'fraction_numerical': 0.025164266741227456, 'mean_word_length': 1.7804119704624952, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1621130', 'n_tokens_mistral': 2435, 'n_tokens_neox': 2242, 'n_words': 387}