Exemple #1
0
def home(request, code=None):
	form = SignupForm(request.POST or None)
	if request.method == 'POST':
		if form.is_valid():
			signup = form.save()
			request.session['code'] = base36.base36encode(signup.pk)
						
			if code:
				try:
					signup_inviter = Signup.objects.get(pk=base36.base36decode(code.upper()))
					signup_inviter.invitees = F('invitees') + 1
					signup_inviter.save()
				except Exception, e:
					pass

			return redirect(reverse('launch_app_success'))
		else:
			# If user has signed up already, show the invite code
			try:
				signup = Signup.objects.get(email=form.data.get('email', ''))
				return render_to_response('launch/already_registered.html', {
					'code': base36.base36encode(signup.pk).lower()
				}, context_instance=RequestContext(request))
			except:
				pass
  def __update_given_submissions(self, submissions):
    for submission in submissions:
      submission_id = base36decode(submission.id)
      if not self.db_manager.row_exists(submission_id):
        s = Submission.from_reddit_api(submission)
        self.db_manager.insert_submission(s)
      else:
        # if submission does exist, update its score
        new_submission = Submission.from_reddit_api(submission)
        # existing_submission =
        query = 'SELECT * FROM submissions WHERE id = %d;' % submission_id
        existing_submissions = [Submission(x) for x in self.db_manager.query(query)]
        assert(len(existing_submissions) == 1)
        existing_submission = existing_submissions[0]
        #print "existing score: ", existing_submission.score
        #print "new score: ", new_submission.score
        if existing_submission.score != new_submission.score:
          #print "going to replace old submission!"
          #print "NEW_SUBMISSION: ", new_submission.to_tuple()
          #print "BEFORE: ", existing_submission.to_tuple()
          existing_submission.score = new_submission.score
          #print "AFTER: ", existing_submission.to_tuple()
          #time.sleep(5)
          self.db_manager.replace_submission(existing_submission)

      # Debug printing:
      if self.db_manager.new_rows_written % 100 == 0 and self.db_manager.new_rows_written != 0:
          print "Entries written so far: ", self.db_manager.new_rows_written, " [", self.db_manager.rows_written, " total]"
Exemple #3
0
	def get(self):
		url = str(self.request.url)
		split = url.split('/')
		base36short = split[len(split)-1]
		short = base36.base36decode(base36short)
		print short
		key_ = models.ImageKeyRel.gql("WHERE short = :1", short).get()
		img = db.get(key_.key_)
		if img.image:
			self.response.headers['Content-Type'] = 'image/png'
			self.response.out.write(img.image)
		else:
			self.error(404)
Exemple #4
0
 def get(self):
     url = str(self.request.url)
     split = url.split('/')
     base36short = split[len(split) - 1]
     short = base36.base36decode(base36short)
     print short
     key_ = models.ImageKeyRel.gql("WHERE short = :1", short).get()
     img = db.get(key_.key_)
     if img.image:
         self.response.headers['Content-Type'] = 'image/png'
         self.response.out.write(img.image)
     else:
         self.error(404)
  def __update_given_submission(self, submission):
    submission_id = base36decode(submission.id)

    if not self.db_manager.row_exists(submission_id):
      s = Submission.from_reddit_api(submission)
      self.db_manager.insert_submission(s)
    else:
      new_submission = Submission.from_reddit_api(submission)
      query = 'SELECT * FROM submissions WHERE id = %d;' % submission_id
      existing_submissions = [Submission(x) for x in self.db_manager.query(query)]
      assert(len(existing_submissions) == 1)
      existing_submission = existing_submissions[0]

      if existing_submission.score != new_submission.score:
        existing_submission.score = new_submission.score
        self.db_manager.replace_submission(existing_submission)
  def from_reddit_api(r):
    # TODO: submission is not being set properly
    #selftext = None if not r.selftext else r.selftext
    # media = None if not r.media else json.dumps(r.media)
    #media_embed = None  # useless feild now
    # media_embed = None if not r.media_embed else json.dumps(r.media_embed)

    # NOTE: media is just being set to None because I'll set it myself after
    # looking through the file
    submission_tuple = (base36decode(r.id), 0, r.title, r.score, int(r.over_18),
                        r.created, r.subreddit.display_name, r.permalink)
    s = Submission(submission_tuple)
    # Moved the code below to reddit_imgur_main.py
    # Imgur.load_imgur_information_for_submission(s)
    # print s
    return s
Exemple #7
0
def hello():
    url = request.args.get("url", "")
    alias = request.args.get("alias", "")
    origin_url = redis_get_url_by_key(alias)
    if origin_url == url:
        return "%s is created!" % alias;
    if origin_url is None and len(alias) > 0:
        redis_set_number_url(base36decode(alias), url)
        return "%s is created!" % alias;
    alias = redis_get_alias_by_url(url)
    if alias is not None:
        return "%s is created!" % alias;

    count = int(redis_get_unused_number())
    alias = base36encode(count)
    redis_set_number_url(count, url)
    return "%s is created!" % alias;
  def update_all_reddits(self, smallest_id, largest_id):
    # http://www.reddit.com/dev/api
    # t3_ means link
    # example:
    # http://www.reddit.com/by_id/t3_zcd40t3_zcd41,t3_zcd42,t3_zcd43/.json
    print "Attempting to download all reddit submissions between id: ", smallest_id, " and ", largest_id
    i = 0
    entries_written = 0
    entries_non_existent = 0
    while smallest_id < largest_id:
      i += 1
      # Debug printing every 50 runs (after processing 5000 entries) ~ every 100 seconds:
      if (i - 1) % 50 == 0:
        #if self.db_manager.new_rows_written % 1000 == 0 and self.db_manager.new_rows_written != 0:
        print "Entries written: ", entries_written, " [Non-existent: ", entries_non_existent, "] - on id: ", smallest_id


      url = "http://www.reddit.com/by_id/"

      submissions_to_fetch_int = set()


      # Queue up 100 submissions to fetch which the database does not currently contain
      while smallest_id < largest_id and len(submissions_to_fetch_int) < ENTRIES_TO_FETCH:
        # print "row_id = ", most_recent_id
        if not self.db_manager.row_exists(smallest_id):
          submissions_to_fetch_int.add(smallest_id)
        smallest_id += 1

      # Create a URL string for the query
      submissions_to_fetch_str = []
      for s in submissions_to_fetch_int:
        submissions_to_fetch_str.append("t3_" + base36encode(s))
      url += ','.join(submissions_to_fetch_str)

      # Query for the submissions
      submissions = None
      try:
        submissions = self.r.request_json(url, params={'limit': 100}, data=None, as_objects=True, retry_on_error=True)
        # print submissions
        submissions = submissions['data']['children']
      except:
        print "Error when trying to fetch url: ", url

      submissions_fetched_int = set()
      if submissions:
        for submission in submissions:
          self.__update_given_submission(submission)
          entries_written += 1
          submission_id = base36decode(submission.id)
          submissions_fetched_int.add(submission_id)



      # subtract submissions_fetched_int from submissions_to_fetch_int

      submissions_not_fetched = submissions_to_fetch_int.difference(submissions_fetched_int)
      for submission_id in submissions_not_fetched:
        # Mark nonexistent entries
        if not self.db_manager.row_exists(submission_id):
          non_existent_entry = Submission.non_existent_submission(submission_id)
          self.db_manager.insert_submission(non_existent_entry)
          entries_non_existent += 1
 def get_most_recent_id(self):
   url = "http://www.reddit.com/new"
   submissions = self.r.request_json(url, params=None, data=None, as_objects=True, retry_on_error=True)
   submissions = submissions['data']['children']
   submission = submissions[0]
   return base36decode(submission.id)
Exemple #10
0
def redis_get_url_by_key(key):
    if len(key) > 0 and r.hexists(REDIS_NUMBER2URL, base36decode(key)):
        return r.hget(REDIS_NUMBER2URL, base36decode(key))
    return None
Exemple #11
0
from flask import Flask, request

# redis map: ShortUrl.Urls table: number:url
# redis map: ShortUrl.Alias table: number:alias
# redis map: ShortUrl.Url-Number table: url:number

REDIS_COUNT = 'ShortUrl.Count'
REDIS_NUMBER2URL = 'ShortUrl.Num2Urls'
REDIS_URL2NUMBER = 'ShortUrl.Url2Nums'

app = Flask(__name__)
r = redis.StrictRedis(host='localhost', port=6379, db=0)
if r.get(REDIS_COUNT) is None:
    r.set(REDIS_COUNT,0)

r.hset(REDIS_NUMBER2URL, str(base36decode('a')), "http://www.qq.com")
r.hset(REDIS_NUMBER2URL, str(base36decode('b')), "http://www.sina.com")

r.hset(REDIS_URL2NUMBER, "http://www.qq.com", str(base36decode('a')))
r.hset(REDIS_URL2NUMBER, "http://www.sina.com", str(base36decode('b')))

table = {
"a":"http://www.qq.com",
"b":"http://www.sina.com"
}

def redis_get_url_by_key(key):
    if len(key) > 0 and r.hexists(REDIS_NUMBER2URL, base36decode(key)):
        return r.hget(REDIS_NUMBER2URL, base36decode(key))
    return None
Exemple #12
0
#!/usr/bin/env python2
from pwn import *
from morse_talk import decode, encode
import binascii
import hashlib
from base36 import base36decode, base36encode

r = remote("morset.pwning.xxx", 11821)
p = r.recv()
print binascii.unhexlify("0{:02x}".format(base36decode(decode(p))))

temp = binascii.unhexlify("0{:02x}".format(base36decode(
    decode(p)))).split("SHA256(")[1][:-2]
print "to hash is: %s" % temp
h = hashlib.new("sha256")
h.update(temp)
print "hexdigest: %s" % h.hexdigest()
print "hexlified: %s" % binascii.hexlify(h.hexdigest())
print "base36ed: %s" % base36encode(int(binascii.hexlify(h.hexdigest()), 16))

r.sendline(encode(base36encode(int(binascii.hexlify(h.hexdigest()), 16))))

import time
time.sleep(1)
rep = r.recv().rstrip().strip()
print "rep is: %s" % rep
print binascii.unhexlify("{:02x}".format(base36decode(decode(rep))))
Exemple #13
0
#!/usr/bin/env python2
from pwn import *
from morse_talk import decode, encode
import binascii
import hashlib
from base36 import base36decode, base36encode

r = remote("morset.pwning.xxx", 11821)
p = r.recv()
print binascii.unhexlify("0{:02x}".format(base36decode(decode(p))))

temp = binascii.unhexlify("0{:02x}".format(base36decode(decode(p)))).split("SHA256(")[1][:-2]
print "to hash is: %s" % temp
h = hashlib.new("sha256")
h.update(temp)
print "hexdigest: %s" % h.hexdigest()
print "hexlified: %s" % binascii.hexlify(h.hexdigest())
print "base36ed: %s" % base36encode(int(binascii.hexlify(h.hexdigest()),16))

r.sendline(encode(base36encode(int(binascii.hexlify(h.hexdigest()),16))))

import time; time.sleep(1)
rep = r.recv().rstrip().strip()
print "rep is: %s" % rep
print binascii.unhexlify("{:02x}".format(base36decode(decode(rep))))