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

import os
import re
import uuid
import bottle
import pymongo

bottle.debug(True)

mongo_con = pymongo.Connection(os.environ['OPENSHIFT_MONGODB_DB_HOST'],
                               int(os.environ['OPENSHIFT_MONGODB_DB_PORT']))

mongo_db = mongo_con[os.environ['OPENSHIFT_APP_NAME']]
mongo_db.authenticate(os.environ['OPENSHIFT_MONGODB_DB_USERNAME'],
                      os.environ['OPENSHIFT_MONGODB_DB_PASSWORD'])


# client = pymongo.MongoClient()
 
# mongo_db = client.amiproductive
# mongo_db.authenticate(os.environ['OPENSHIFT_MONGODB_DB_USERNAME'],
#                      os.environ['OPENSHIFT_MONGODB_DB_PASSWORD'],
#                      'amiproductive')

def user_find(data):
  if not data: return None
  return mongo_db.users.find_one({ '_id': data})

# @bottle.route('/', method="POST")
# def index():
#   data = bottle.request.forms
#   if data.get('email'):
#     # check for pre existence
#     tuser = user_find(data.get('email'))
#     if tuser:
#       return bottle.template('index', result='You are already registered!')
#     else:
#       nuser = {
#         '_id': data.get('email'),
#         'pw': data.get('password')
#       }
#       userid = mongo_db.users.insert(nuser)
#       return bottle.template('welcome', result='You\'ve been signed up!', email=data.get('email'))
#   else:
#     return bottle.template('index', result=None)

@bottle.route('/', method="GET")
def index():
  return bottle.template('index', mac=None)

@bottle.route('/data', method="POST")
def data():
  return bottle.request.forms.get('data')

@bottle.route('/receiveData', method="POST")
def receiveData():
  post = bottle.request.forms
  good = []
  bad = ['https://facebook.com']

  if post.get('data'):
    info = user_find('10:10:10:10')
    url = re.search("(?P<url>https?://[^\s]+)", post.get('data')).group("url")
    
    if info:
      if url in good:
        mongo_db.users.update(
          { '_id' : '10:10:10:10' },
          { '$inc' : { 'good' : 1, 'bad' : -1 } }
        )
      elif url in bad:
        mongo_db.users.update(
          { '_id' : '10:10:10:10' },
          { '$inc' : { 'good' : -1, 'bad' : 1 } }
        )
      mongo_db.traffic.update(
        { 'url' : url },
        { '$inc' : { 'count' : 1 } }
      )

    else:
      connection = {
        '_id': '10:10:10:10',
        'url': url,
        'count': 1
      }
      userid = mongo_db.traffic.insert(connection)

# def snippet_create(user, code):
#   nsnippet = {
#     '_id': uuid.uuid4().hex,
#     'uid': user['_id'],
#     'code': code
#     }
#   mongo_db.snippets.insert(nsnippet)
#   return nsnippet

# def note_create(snip, user, text):
#   nnote = {
#     '_id': uuid.uuid4().hex,
#     'uid': user['_id'],
#     'cid': snip['_id'],
#     'text': text
#   }
#   mongo_db.notes.insert(nnote)<commit_msg>Update data capturing stuff.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import re
import uuid
import bottle
import pymongo

bottle.debug(True)

mongo_con = pymongo.Connection(os.environ['OPENSHIFT_MONGODB_DB_HOST'],
                               int(os.environ['OPENSHIFT_MONGODB_DB_PORT']))

mongo_db = mongo_con[os.environ['OPENSHIFT_APP_NAME']]
mongo_db.authenticate(os.environ['OPENSHIFT_MONGODB_DB_USERNAME'],
                      os.environ['OPENSHIFT_MONGODB_DB_PASSWORD'])


# client = pymongo.MongoClient()
 
# mongo_db = client.amiproductive
# mongo_db.authenticate(os.environ['OPENSHIFT_MONGODB_DB_USERNAME'],
#                      os.environ['OPENSHIFT_MONGODB_DB_PASSWORD'],
#                      'amiproductive')

def user_find(data):
  if not data: return None
  return mongo_db.users.find_one({ '_id': data})

def url_find(data):
  if not data: return None
  return mongo_db.traffic.find_one({ 'url': data})

# @bottle.route('/', method="POST")
# def index():
#   data = bottle.request.forms
#   if data.get('email'):
#     # check for pre existence
#     tuser = user_find(data.get('email'))
#     if tuser:
#       return bottle.template('index', result='You are already registered!')
#     else:
#       nuser = {
#         '_id': data.get('email'),
#         'pw': data.get('password')
#       }
#       userid = mongo_db.users.insert(nuser)
#       return bottle.template('welcome', result='You\'ve been signed up!', email=data.get('email'))
#   else:
#     return bottle.template('index', result=None)

@bottle.route('/', method="GET")
def index():
  return bottle.template('index', mac=None)

@bottle.route('/data', method="POST")
def data():
  return bottle.request.forms.get('data')

@bottle.route('/receiveData', method="POST")
def receiveData():
  post = bottle.request.forms
  good = []
  bad = ['https://facebook.com']

  if post.get('data'):
    info = user_find('10:10:10:10')
    url = re.search("(?P<url>https?://[^\s]+)", post.get('data')).group("url")
    
    if info:
      if url in good:
        mongo_db.users.update(
          { '_id' : '10:10:10:10' },
          { '$inc' : { 'good' : 1, 'bad' : -1 } }
        )
      elif url in bad:
        mongo_db.users.update(
          { '_id' : '10:10:10:10' },
          { '$inc' : { 'good' : -1, 'bad' : 1 } }
        )

    traffic = url_find(url)
    if traffic:
      mongo_db.traffic.update(
        { 'url' : url },
        { '$inc' : { 'count' : 1 } }
      )
    else:
      connection = {
        '_id': '10:10:10:10',
        'url': url,
        'count': 1
      }
      userid = mongo_db.traffic.insert(connection)

# def snippet_create(user, code):
#   nsnippet = {
#     '_id': uuid.uuid4().hex,
#     'uid': user['_id'],
#     'code': code
#     }
#   mongo_db.snippets.insert(nsnippet)
#   return nsnippet

# def note_create(snip, user, text):
#   nnote = {
#     '_id': uuid.uuid4().hex,
#     'uid': user['_id'],
#     'cid': snip['_id'],
#     'text': text
#   }
#   mongo_db.notes.insert(nnote)
{'fraction_non_alphanumeric': 0.18101694915254238, 'fraction_numerical': 0.013898305084745762, 'mean_word_length': 2.720680958385876, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '458026', 'n_tokens_mistral': 2201, 'n_tokens_neox': 2149, 'n_words': 375}