<commit_before># Fiend - A Python module for accessing Zynga's Words with Friends
# Copyright (C) 2011 <NAME> <<EMAIL>>
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import httplib2
httplib2.debuglevel = 1

import xml.etree.ElementTree as etree

USER_AGENT = 'WordsWithFriendsAndroid/3.51'
DEVICE_OS = '2.3.3'
DEVICE_ID = 'ADR6300'

class Fiend:
    def __init__(self, authorization, userAgent=USER_AGENT, deviceOs=DEVICE_OS, deviceId=DEVICE_ID):
        self.authorization = authorization
        self.userAgent = userAgent
        self.deviceOs = deviceOs
        self.deviceId = deviceId

        self.http = httplib2.Http();

    def getGames(self):
        params = {'game_type': 'WordGame', 'include_invitations': 'true', 'games_since': '1970-0-1T0:0:0-00:00', 'moves_since': '0', 'chat_messages_since': '0', 'get_current_user': 'true'}
        data = self.serverGet('games', params)
        tree = etree.parse(data)

        gamesData = {}
        games = tree.getroot()
        for game in games:
            pass

        return gamesData

    # Internal methods
    def serverGet(self, call, params):
        url = self.makeUrl(call, params)
        headers = {'User-Agent': USER_AGENT, 'Content-Type': 'application/xml', 'Authorization': self.authorization, 'Device-OS': self.deviceOs, 'Device-Id': self.deviceId, 'Accept': 'text/xml', 'Cache-Control': 'no-cache', 'Pragma': 'no-cache'}
        response, content = self.http.request(url, headers=headers)

        # TODO: Check response to make sure all is well
        return content

    def makeUrl(self, call, params):
        WWF_URL = 'https://wordswithfriends.zyngawithfriends.com/'
        url = WWF_URL + call + '?'
        url += '&'.join([str(k) + '=' + str(v) for k, v in params.iteritems()])
        return url
<commit_msg>make gamesData a lazy loaded property<commit_after># Fiend - A Python module for accessing Zynga's Words with Friends
# Copyright (C) 2011 <NAME> <<EMAIL>>
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import httplib2
httplib2.debuglevel = 1

import xml.etree.ElementTree as etree

USER_AGENT = 'WordsWithFriendsAndroid/3.51'
DEVICE_OS = '2.3.3'
DEVICE_ID = 'ADR6300'

class Fiend(object):
    def __init__(self, authorization, userAgent=USER_AGENT, deviceOs=DEVICE_OS, deviceId=DEVICE_ID):
        self.authorization = authorization
        self.userAgent = userAgent
        self.deviceOs = deviceOs
        self.deviceId = deviceId

        self.http = httplib2.Http();

        self._gamesData = {}

    @property
    def gamesData(self):
        """Data about your games"""
        if not self._gamesData:
            self.refreshGamesData()

        return self._gamesData

    def refreshGamesData(self):
        params = {'game_type': 'WordGame', 'include_invitations': 'true', 'games_since': '1970-0-1T0:0:0-00:00', 'moves_since': '0', 'chat_messages_since': '0', 'get_current_user': 'true'}
        data = self.serverGet('games', params)
        games = etree.fromstring(data)

        for game in games:
            pass

    # Internal methods
    def serverGet(self, call, params):
        url = self.makeUrl(call, params)
        headers = {'User-Agent': USER_AGENT, 'Content-Type': 'application/xml', 'Authorization': self.authorization, 'Device-OS': self.deviceOs, 'Device-Id': self.deviceId, 'Accept': 'text/xml', 'Cache-Control': 'no-cache', 'Pragma': 'no-cache'}
        response, content = self.http.request(url, headers=headers)

        # TODO: Check response to make sure all is well
        return content

    def makeUrl(self, call, params):
        WWF_URL = 'https://wordswithfriends.zyngawithfriends.com/'
        url = WWF_URL + call + '?'
        url += '&'.join([str(k) + '=' + str(v) for k, v in params.iteritems()])
        return url
{'fraction_non_alphanumeric': 0.11492627751969299, 'fraction_numerical': 0.01373459907089477, 'mean_word_length': 3.3211169284467714, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '386330', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1474, 'n_words': 488}