<commit_before>#!/usr/bin/env python

import os,sys,time,json,urllib2
from random import randint
from json import JSONEncoder

class Update:
  def __init__(self, name, version, arch, repository, baseversion):
    self.name = name
    self.version = version
    self.architecture = arch
    self.repository = repository
    self.baseversion = baseversion

class System:
  def __init__(self, name, urn, os, address, reboot_required):
    self.name = name
    self.urn = urn
    self.os = os
    self.address = address
    self.reboot_required = reboot_required
    self.packageupdates = list()

  def addUpdate(self, update):
    self.packageupdates.append(update)

class MyEncoder(JSONEncoder):
    def default(self, o):
        return o.__dict__

# Demodata
urn = 'vm1'
sys = System(urn, urn, "Ubuntu 15.10", "127.0.0.1", True)
sys.addUpdate(Update(name="vim", version="demoupdate", arch="amd64", repository="demorepo", baseversion="2:7.4.712-2ubuntu4"))
sys.addUpdate(Update(name="dnsutils", version="demoupdate", arch="amd64", repository="demorepo", baseversion="1:9.9.5.dfsg-11ubuntu1"))

#url = 'http://upd89.org/api.php'
url = 'http://cc.upd89.org/v1/system/' + urn + '/notify'

print("Sending to server (notify system " + urn + ")...")
req = urllib2.Request(url)
req.add_header('Content-Type', 'application/json')
response = urllib2.urlopen(req, json.dumps(sys, cls=MyEncoder))
print("Response:")
print(response.read())

<commit_msg>extracted classes<commit_after>#!/usr/bin/env python

import os,sys,time,json,urllib2
from random import randint
from json import JSONEncoder

from classes.update import Update
from classes.system_notify import System
from classes.encoder import MyEncoder

# Demodata
urn = 'vm1'
sys = System(urn, urn, "Ubuntu 15.10", "127.0.0.1", True)
sys.addUpdate(Update(name="vim", version="demoupdate", arch="amd64", repository="demorepo", baseversion="2:7.4.712-2ubuntu4"))
sys.addUpdate(Update(name="dnsutils", version="demoupdate", arch="amd64", repository="demorepo", baseversion="1:9.9.5.dfsg-11ubuntu1"))

#url = 'http://upd89.org/api.php'
url = 'http://cc.upd89.org/v1/system/' + urn + '/notify'

print("Sending to server (notify system " + urn + ")...")
req = urllib2.Request(url)
req.add_header('Content-Type', 'application/json')
response = urllib2.urlopen(req, json.dumps(sys, cls=MyEncoder))
print("Response:")
print(response.read())


{'fraction_non_alphanumeric': 0.1611952861952862, 'fraction_numerical': 0.03198653198653199, 'mean_word_length': 5.158031088082901, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '219538', 'n_tokens_mistral': 876, 'n_tokens_neox': 830, 'n_words': 172}