rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
try: queryset = Document.search.query(obj) results = queryset.set_options(mode="SPH_MATCH_EXTENDED2")\ .order_by('-dateFiled')[:20] except: results = [] | queryset = Document.search.query(str(obj)) results = queryset.set_options(mode="SPH_MATCH_EXTENDED2")\ .order_by('-dateFiled') | def items(self, obj): # Do a Sphinx query here. Return the first 20 results try: queryset = Document.search.query(obj) results = queryset.set_options(mode="SPH_MATCH_EXTENDED2")\ .order_by('-dateFiled')[:20] except: results = [] return results |
import datetime | def items(self, obj): # Do a Sphinx query here. Return the first 20 results obj = preparseQuery(obj) queryset = Document.search.query(obj) results = queryset.set_options(mode="SPH_MATCH_EXTENDED2")\ .order_by('-dateFiled') return results | |
.order_by('-dateFiled') | .order_by('-dateFiled').filter(dateFiled__gt=datetime.date(1950, 1, 1)) | def items(self, obj): # Do a Sphinx query here. Return the first 20 results obj = preparseQuery(obj) queryset = Document.search.query(obj) results = queryset.set_options(mode="SPH_MATCH_EXTENDED2")\ .order_by('-dateFiled') return results |
cites = Citation.objects.filter(caseNameShort__in = [case.replace('_', ' ').replace('-', ' '), case]) | cites = Citation.objects.filter(caseNameShort__in = [case.replace('-', ' ').replace('_', '-'), case]) | def viewCases(request, court, case): """Take a court and a caseNameShort, and display what we know about that case. """ # get the court information from the URL ct = Court.objects.get(courtUUID = court) # try looking it up by casename. Failing that, try the caseNumber. # replace spaces with hyphens to undo the URLizi... |
if not options.scrapeID and options.parseID: | if not options.scrapeID and not options.parseID: | def main(): usage = "usage: %prog (-s SCRAPEID | -p PARSEID) [-v | -V]" parser = OptionParser(usage) parser.add_option('-s', '--scrape', dest='scrapeID', metavar='SCRAPEID', help="The court to scrape and parse") parser.add_option('-p', '--parse', dest='parseID', metavar='PARSEID', help="The court to only parse") parser... |
attributeRegex = re.compile('(@.*)') attributes = re.findall('@.*\W', query) | attributes = re.findall('@\w*', query) badAttrs = [] | def showResults(request, queryType="search"): """Show the results for a query as either an alert or a search""" if queryType == "alert/preview": queryType = "alert" elif queryType == "search/results": queryType = "search" try: query = request.GET['q'] except: # if somebody is URL hacking at /search/results/ or alert/p... |
if attribute.lower() not in "@court @casename @docstatus @doctext": messages.add_message(request, messages.INFO, 'We ran your search, but found invalid attributes.<br> \ Valid attributes are @court, @caseName, @docStatus and @docText') | if attribute.lower() != ("@court" or "@casename" or "@docstatus" or "@doctext"): badAttrs.append(attribute) if len(badAttrs) == 1: messageText = 'We completed your search, but <strong>' + \ oxford_comma(badAttrs) + '</strong> is not a valid attribute.<br>\ Valid attributes are @court, @caseName, @docStatus and @docTe... | def showResults(request, queryType="search"): """Show the results for a query as either an alert or a search""" if queryType == "alert/preview": queryType = "alert" elif queryType == "search/results": queryType = "search" try: query = request.GET['q'] except: # if somebody is URL hacking at /search/results/ or alert/p... |
print "username is: " + username | def register(request): """allow an anonymous user to register""" from django.contrib.auth.forms import UserCreationForm if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): cd = form.cleaned_data new_user = form.save() username = str(cd['username']) print "username is: " + username pa... | |
print "password is: " + password | def register(request): """allow an anonymous user to register""" from django.contrib.auth.forms import UserCreationForm if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): cd = form.cleaned_data new_user = form.save() username = str(cd['username']) print "username is: " + username pa... | |
tree = etree.parse(req) | contents = req.read() if '&' in contents: punctuationRegex = re.compile(" & ") contents = re.sub(punctuationRegex, " & ", contents) tree = etree.fromstring(contents) else: tree = etree.fromstring(contents) | def scrapeCourt(courtID, result): if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shall. """ url = "http://www.ca1.uscourts.gov/opinions/opinionrss.php" ct = Court.objects.get(courtUUID='ca1') req = urllib2.urlopen(url) tree = etree.parse(req) c... |
redirect_to = settings.LOGIN_REDIRECT_URL | redirect_to = LOGIN_REDIRECT_URL | def register(request): """allow only an anonymous user to register""" redirect_to = request.REQUEST.get('next', '') # security checks: # Light security check -- make sure redirect_to isn't garbage. if not redirect_to or ' ' in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL # Heavier security check -- redirec... |
formattedToday = str(today.year) + str(today.month) + str(today.day) | formattedStartDate = str(today.year) + '03' + '07' | def scrapeCourt(courtID, result): if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shall. This is the second version of this court. Good times. """ url = "http://www.ca1.uscourts.gov/opinions/opinionrss.php" ct = Court.objects.get(courtUUID='ca1')... |
formattedToday + "&IW_FILTER_DATE_BEFORE=&IW_BATCHSIZE=50&" +\ | formattedStartDate + "&IW_FILTER_DATE_BEFORE=&IW_BATCHSIZE=50&" +\ | def scrapeCourt(courtID, result): if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shall. This is the second version of this court. Good times. """ url = "http://www.ca1.uscourts.gov/opinions/opinionrss.php" ct = Court.objects.get(courtUUID='ca1')... |
print "Duplicate file found, appending -2" filename = filename[0:string.rfind(filename, ".")] + "-2" \ | print "Duplicate file found, appending 2" filename = filename[0:string.rfind(filename, ".")] + "2" \ | def update_date(doc, simulate): time.sleep(1) # take the doc, check its dateFiled field, make a hardlink to the PDF # location, and update the database if doc.dateFiled != None: dateFiled = doc.dateFiled else: # break from this function. print "\n***No dateFiled value for doc: " + str(doc.documentUUID) + ". Punting.***... |
results = sorted(results, key=getDateFiledOrReturnZero, reverse=True) | results = sorted(results[0:results.count()], key=getDateFiledOrReturnZero, reverse=True) | def showResults(request): """Show the results for a query""" try: query = request.GET['q'] except: # if somebody is URL hacking at /search/results/ query = "" # this handles the alert creation form. if request.method == 'POST': from alert.userHandling.models import Alert # an alert has been created alertForm = Create... |
if attribute.lower() != ("@court" or "@casename" or "@docstatus" or "@doctext"): | if validRegex.search(attribute.lower()) == None: | def showResults(request, queryType="search"): """Show the results for a query as either an alert or a search""" if queryType == "alert/preview": queryType = "alert" elif queryType == "search/results": queryType = "search" try: query = request.GET['q'] except: # if somebody is URL hacking at /search/results/ or alert/p... |
else: | messages.add_message(request, messages.INFO, messageText) elif len(badAttrs) > 1: | def showResults(request, queryType="search"): """Show the results for a query as either an alert or a search""" if queryType == "alert/preview": queryType = "alert" elif queryType == "search/results": queryType = "search" try: query = request.GET['q'] except: # if somebody is URL hacking at /search/results/ or alert/p... |
words = re.split('\s', text) line = [] for word in words: if INLINE_PERIOD.search(word) or UC_ELSEWHERE.match(word): line.append(word) continue if SMALL_WORDS.match(word): line.append(word.lower()) continue if BIG_WORDS.match(word): line.append(word.upper()) continue line.append(CAPFIRST.sub(lambda m: m.group(0).upper(... | match = MAC_MC.match(word) if match: tc_line.append("%s%s" % (match.group(1).capitalize(), match.group(2).capitalize())) continue hyphenated = [] for item in word.split('-'): hyphenated.append(CAPFIRST.sub(lambda m: m.group(0).upper(), item)) tc_line.append("-".join(hyphenated)) | def titlecase(text): """ Titlecases input text This filter changes all words to Title Caps, and attempts to be clever about *un*capitalizing SMALL words like a/an/the in the input. The list of "SMALL words" which are not capped comes from the New York Times Manual of Style, plus 'vs' and 'v'. """ words = re.split(... |
line = " ".join(line) | result = " ".join(tc_line) | def titlecase(text): """ Titlecases input text This filter changes all words to Title Caps, and attempts to be clever about *un*capitalizing SMALL words like a/an/the in the input. The list of "SMALL words" which are not capped comes from the New York Times Manual of Style, plus 'vs' and 'v'. """ words = re.split(... |
line = SMALL_FIRST.sub(lambda m: '%s%s' % ( m.group(1), m.group(2).capitalize() ), line) | result = SMALL_FIRST.sub(lambda m: '%s%s' % ( m.group(1), m.group(2).capitalize() ), result) | def titlecase(text): """ Titlecases input text This filter changes all words to Title Caps, and attempts to be clever about *un*capitalizing SMALL words like a/an/the in the input. The list of "SMALL words" which are not capped comes from the New York Times Manual of Style, plus 'vs' and 'v'. """ words = re.split(... |
line = SMALL_LAST.sub(lambda m: m.group(0).capitalize(), line) | result = SMALL_LAST.sub(lambda m: m.group(0).capitalize(), result) | def titlecase(text): """ Titlecases input text This filter changes all words to Title Caps, and attempts to be clever about *un*capitalizing SMALL words like a/an/the in the input. The list of "SMALL words" which are not capped comes from the New York Times Manual of Style, plus 'vs' and 'v'. """ words = re.split(... |
line = SUBPHRASE.sub(lambda m: '%s%s' % ( m.group(1), m.group(2).capitalize() ), line) | result = SUBPHRASE.sub(lambda m: '%s%s' % ( m.group(1), m.group(2).capitalize() ), result) processed.append(result) | def titlecase(text): """ Titlecases input text This filter changes all words to Title Caps, and attempts to be clever about *un*capitalizing SMALL words like a/an/the in the input. The list of "SMALL words" which are not capped comes from the New York Times Manual of Style, plus 'vs' and 'v'. """ words = re.split(... |
return line class TitlecaseTests(unittest.TestCase): """Tests to ensure titlecase follows all of the rules""" def test_q_and_a(self): """Testing: Q&A With Steve Jobs: 'That's What Happens In Technology' """ text = titlecase( "Q&A with steve jobs: 'that's what happens in technology'" ) result = "Q&A With Steve Jobs: ... | return "\n".join(processed) | def titlecase(text): """ Titlecases input text This filter changes all words to Title Caps, and attempts to be clever about *un*capitalizing SMALL words like a/an/the in the input. The list of "SMALL words" which are not capped comes from the New York Times Manual of Style, plus 'vs' and 'v'. """ words = re.split(... |
{'form': form, 'username': username, 'password': password}, RequestContext(request)) | {'form': form, 'username': username, 'password': password, 'redirect_to': redirect_to}, RequestContext(request)) | def register(request): """allow only an anonymous user to register""" if request.user.is_anonymous(): from django.contrib.auth.forms import UserCreationForm if request.method == 'POST': form = UserCreationFormExtended(request.POST) if form.is_valid(): cd = form.cleaned_data # make a new user, and then a new UserProfil... |
validRegex = re.compile(r'(@court |@casename |@docstatus |@doctext )') | validRegex = re.compile(r'^@court$|^@casename$|^@docstatus$|^@doctext$') | def showResults(request, queryType="search"): """Show the results for a query as either an alert or a search""" if queryType == "alert/preview": queryType = "alert" elif queryType == "search/results": queryType = "search" try: query = request.GET['q'] except: # if somebody is URL hacking at /search/results/ or alert/p... |
formattedToday = str(today.year) + '03' + '07' | formattedToday = str(today.year) + str(today.month) + str(today.day) | def scrapeCourt(courtID, result): if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shall. This is the second version of this court. Good times. """ url = "http://www.ca1.uscourts.gov/opinions/opinionrss.php" ct = Court.objects.get(courtUUID='ca1')... |
formattedToday + "&IW_FILTER_DATE_BEFORE=&IW_BATCHSIZE=20&" +\ | formattedToday + "&IW_FILTER_DATE_BEFORE=&IW_BATCHSIZE=50&" +\ | def scrapeCourt(courtID, result): if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shall. This is the second version of this court. Good times. """ url = "http://www.ca1.uscourts.gov/opinions/opinionrss.php" ct = Court.objects.get(courtUUID='ca1')... |
pass | def scrapeCourt(courtID, result): if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shall. This is the second version of this court. Good times. """ url = "http://www.ca1.uscourts.gov/opinions/opinionrss.php" ct = Court.objects.get(courtUUID='ca1')... | |
caseName = caseName.replace(' ', ' ').strip() | caseName = caseName.replace(' ', ' ').replace('%20', ' ').strip() caseNum = caseNum.replace(' ', ' ').replace('%20', ' ').strip() | def hasDuplicate(caseNum, caseName): """takes a caseName and a caseNum, and checks if the object exists in the DB. If it doesn't, then it puts it in. If it does, it returns it. """ caseName = caseName.replace(' ', ' ').strip() # check for duplicates, make the object in their absence cite, created = Citation.obje... |
formattedToday = str(today.year) + str(today.month) + str(today.day) | formattedToday = str(today.year) + str(today.month) + '07' | def scrapeCourt(courtID, result): if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shall. """ url = "http://www.ca1.uscourts.gov/opinions/opinionrss.php" ct = Court.objects.get(courtUUID='ca1') req = urllib2.urlopen(url) # this code gets rid of e... |
def emailer(rate): | def emailer(rate, verbose): | def emailer(rate): """This will load all the users each day/week/month, and send them emails.""" # remap the FREQUENCY variable from the model so the human keys relate back # to the indices rates = {} for r in FREQUENCY: rates[r[1].lower()] = r[0] RATE = rates[rate] # sphinx likes time in UnixTime format, which the be... |
if verbose: print "There were " + str(results.count()) + \ " hits for the alert \"" + alert.alertText + \ "\". Here are the first 0-20: " + str(results) | def emailer(rate): """This will load all the users each day/week/month, and send them emails.""" # remap the FREQUENCY variable from the model so the human keys relate back # to the indices rates = {} for r in FREQUENCY: rates[r[1].lower()] = r[0] RATE = rates[rate] # sphinx likes time in UnixTime format, which the be... | |
if hits.count() > 0: | if len(hits) > 0: | def emailer(rate): """This will load all the users each day/week/month, and send them emails.""" # remap the FREQUENCY variable from the model so the human keys relate back # to the indices rates = {} for r in FREQUENCY: rates[r[1].lower()] = r[0] RATE = rates[rate] # sphinx likes time in UnixTime format, which the be... |
if verbose: print "email_text: " + str(email_text) | def emailer(rate): """This will load all the users each day/week/month, and send them emails.""" # remap the FREQUENCY variable from the model so the human keys relate back # to the indices rates = {} for r in FREQUENCY: rates[r[1].lower()] = r[0] RATE = rates[rate] # sphinx likes time in UnixTime format, which the be... | |
help="The rate to send emails") | help="The rate to send emails") parser.add_option('-v', '--verbose', action="store_true", dest='verbose', default=False, help="Display variable values during execution") | def main(): usage = "usage: %prog -r RATE | --rate=RATE" parser = OptionParser(usage) parser.add_option('-r', '--rate', dest='rate', metavar='RATE', help="The rate to send emails") (options, args) = parser.parse_args() if not options.rate: parser.error("You must specify a rate") rate = options.rate return emailer(rat... |
return emailer(rate) | verbose = options.verbose return emailer(rate, verbose) | def main(): usage = "usage: %prog -r RATE | --rate=RATE" parser = OptionParser(usage) parser.add_option('-r', '--rate', dest='rate', metavar='RATE', help="The rate to send emails") (options, args) = parser.parse_args() if not options.rate: parser.error("You must specify a rate") rate = options.rate return emailer(rat... |
i = i+1 | i += 1 | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
if dupCount == 3: | if dupCount == 5: | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
caseNumber = trTags[i].td.nextSibling.nextSibling.contents[0].strip() | caseNumber = trTags[i].td.nextSibling.nextSibling.contents[0] | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
dateFiled = trTags[i].td.contents.strip() splitDate = dateFiled[0].split("-") | dateFiled = trTags[i].td.contents[0].strip() splitDate = dateFiled.split("-") | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
upperCaseName = trTags[i].td.nextSibling.nextSibling.nextSibling\ .nextSibling.nextSibling.nextSibling.a.contents[0].strip('[Motion]').strip('[order]') caseNameShort = titlecase(upperCaseName.lower()) | caseNameShort = trTags[i].td.nextSibling.nextSibling.nextSibling\ .nextSibling.nextSibling.nextSibling.a.contents[0]\ .replace('[Motion]', '').replace('[order]', '') caseNameShort = titlecase(caseNameShort.lower()) | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
except: hasDup = False | def hasDuplicate(caseNumber, caseNameShort): """give it a caseNumber and a caseNameShort, and it'll tell you if that is already in the DB""" try: Citation.objects.get(caseNumber = caseNumber, caseNameShort = caseNameShort) print "duplicate found!" hasDup = True except: hasDup = False return hasDup | |
.order_by('-dateFiled')[:20] | .order_by('-dateFiled') | def items(self, obj): # Do a Sphinx query here. Return the first 20 results queryset = Document.search.query(obj) results = queryset.set_options(mode="SPH_MATCH_EXTENDED2")\ .order_by('-dateFiled')[:20] return results |
caseNameShort = caseName, caseNumber = caseNum) | caseNameShort = str(caseName), caseNumber = str(caseNum)) | def hasDuplicate(caseNum, caseName): """takes a caseName and a caseNum, and checks if the object exists in the DB. If it doesn't, then it puts it in. If it does, it returns it. """ # check for duplicates, make the object in their absence cite, created = Citation.objects.get_or_create( caseNameShort = caseName, caseNum... |
print "alertWithResults: " + alertWithResults print "hits: " + hits | print "alertWithResults: " + str(alertWithResults) print "hits: " + str(hits) | def emailer(rate, verbose, simulate): """This will load all the users each day/week/month, and send them emails.""" # remap the FREQUENCY variable from the model so the human keys relate back # to the indices rates = {} for r in FREQUENCY: rates[r[1].lower()] = r[0] RATE = rates[rate] # sphinx likes time in UnixTime f... |
i = 4 | i = 1 | def scrapeCourt(courtID, result): if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shall. """ url = "http://www.ca1.uscourts.gov/opinions/opinionrss.php" ct = Court.objects.get(courtUUID='ca1') req = urllib2.urlopen(url) tree = etree.parse(req) c... |
if verbosity >= 1: | if verbosity >= 2: | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
if dupCount == 3: | if dupCount == 5: | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
if verbosity >= 2: print "Duplicate found at " + str(i) | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... | |
if verbosity >= 2: print "Duplicate found at " + str(i) + '\n' | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... | |
if '/' in caseDates[i].text: splitDate = caseDates[i].text.split('/') elif '-' in caseDates[i].text: splitDate = caseDates[i].text.split('-') year = int("20" + splitDate[2]) caseDate = datetime.date(year, int(splitDate[0]), int(splitDate[1])) doc.dateFiled = caseDate if verbosity >= 2: print "caseDate: " + str(caseDate... | try: if '/' in caseDates[i].text: splitDate = caseDates[i].text.split('/') elif '-' in caseDates[i].text: splitDate = caseDates[i].text.split('-') year = int("20" + splitDate[2]) caseDate = datetime.date(year, int(splitDate[0]), int(splitDate[1])) doc.dateFiled = caseDate if verbosity >= 2: print "caseDate: " + str(cas... | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
if verbosity >= 2: print "start date: " + str(dates) | if verbosity >= 2: print "start date: " + str(todayObject) | def scrapeCourt(courtID, result, verbosity): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shall. """ url =... |
if verbose: print "Now running the query: " + alert.alertText if RATE == 'dly': if verbose: "Now running the search for: " + alert.alertText queryset = Document.search.query(alert.alertText) results = queryset.set_options(mode="SPH_MATCH_EXTENDED2")\ .filter(datefiled=unixTimeToday) elif RATE == 'wly' and today.weekda... | try: if verbose: print "Now running the query: " + alert.alertText if RATE == 'dly': if verbose: "Now running the search for: " + alert.alertText queryset = Document.search.query(alert.alertText) results = queryset.set_options(mode="SPH_MATCH_EXTENDED2")\ .filter(datefiled=unixTimeToday) elif RATE == 'wly' and today.w... | def emailer(rate, verbose, simulate): """This will load all the users each day/week/month, and send them emails.""" # remap the FREQUENCY variable from the model so the human keys relate back # to the indices rates = {} for r in FREQUENCY: rates[r[1].lower()] = r[0] RATE = rates[rate] # sphinx likes time in UnixTime f... |
if results.count() > 0: alertWithResults = [alert, results[0:results.count()]] hits.append(alertWithResults) alert.lastHitDate = datetime.date.today() alert.save() if verbose: print "alertWithResults: " + str(alertWithResults) print "hits: " + str(hits) elif alert.sendNegativeAlert: alertWithResults = [alert, "Non... | try: if results.count() > 0: alertWithResults = [alert, results[0:results.count()]] hits.append(alertWithResults) alert.lastHitDate = datetime.date.today() alert.save() if verbose: print "alertWithResults: " + str(alertWithResults) print "hits: " + str(hits) elif alert.sendNegativeAlert: alertWithResults = [alert,... | def emailer(rate, verbose, simulate): """This will load all the users each day/week/month, and send them emails.""" # remap the FREQUENCY variable from the model so the human keys relate back # to the indices rates = {} for r in FREQUENCY: rates[r[1].lower()] = r[0] RATE = rates[rate] # sphinx likes time in UnixTime f... |
caseDate = caseDateRegex.search(junk).group(1)\ | caseDate = caseDateRegex.search(junk).group(1) | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
while pk < last_pk: for row in queryset.filter(pk__gt=pk)[:chunksize]: pk = row.pk | while documentUUID < last_pk: for row in queryset.filter(documentUUID__gt=documentUUID)[:chunksize]: documentUUID = row.documentUUID | def queryset_iterator(queryset, chunksize=1000): ''''' from: http://djangosnippets.org/snippets/1949/ Iterate over a Django Queryset ordered by the primary key This method loads a maximum of chunksize (default: 1000) rows in its memory at the same time while django normally would load all rows in its memory. Using the... |
def update_dates(doc): | def update_date(doc, simulate): time.sleep(1) | def update_dates(doc): # take the doc, check its dateFiled field, make a hardlink to the PDF # location, and update the database dateFiled = doc.dateFiled local_path = doc.local_path root = settings.MEDIA_ROOT # old link old = os.path.join(root, str(local_path)) # new link year, month, day = str(dateFiled).split("-")... |
dateFiled = doc.dateFiled local_path = doc.local_path | if doc.dateFiled != None: dateFiled = doc.dateFiled else: print "\n***No dateFiled value for doc: " + str(doc.documentUUID) + ". Punting.***\n" return(1) if doc.local_path != "": local_path = doc.local_path else: print "\n***No local_path value for doc: " + str(doc.documentUUID) + ". Punting.***\n" return(2) | def update_dates(doc): # take the doc, check its dateFiled field, make a hardlink to the PDF # location, and update the database dateFiled = doc.dateFiled local_path = doc.local_path root = settings.MEDIA_ROOT # old link old = os.path.join(root, str(local_path)) # new link year, month, day = str(dateFiled).split("-")... |
new = os.path.join(root, year, month, day, old) | new = os.path.join(root, "pdf", year, month, day, filename) | def update_dates(doc): # take the doc, check its dateFiled field, make a hardlink to the PDF # location, and update the database dateFiled = doc.dateFiled local_path = doc.local_path root = settings.MEDIA_ROOT # old link old = os.path.join(root, str(local_path)) # new link year, month, day = str(dateFiled).split("-")... |
mkdir_p(os.path.join(root, year, month, day)) os.link(old, new) | if not simulate: mkdir_p(os.path.join(root, "pdf", year, month, day)) os.link(old, new) doc.local_path = os.path.join("pdf", year, month, day, filename) doc.save() print "***Created new hard link to " + new + " for doc: " + str(doc.documentUUID) + " ***" else: print 'Same. Not updating link.' | def update_dates(doc): # take the doc, check its dateFiled field, make a hardlink to the PDF # location, and update the database dateFiled = doc.dateFiled local_path = doc.local_path root = settings.MEDIA_ROOT # old link old = os.path.join(root, str(local_path)) # new link year, month, day = str(dateFiled).split("-")... |
usage = "usage: %prog (-b BEGIN -e END) | -a" | usage = "usage: %prog (-b BEGIN -e END) | -a [-s]" | def main(): usage = "usage: %prog (-b BEGIN -e END) | -a" parser = OptionParser(usage) parser.add_option('-b', '--begin', dest='begin', matavar="BEGIN", help="The ID in the database where fixing should begin (inclusive).") parser.add_option('-e', '--end', dest='end', metavar="END", help="The ID in the database where fi... |
parser.add_option('-b', '--begin', dest='begin', matavar="BEGIN", | parser.add_option('-b', '--begin', dest='begin', metavar="BEGIN", | def main(): usage = "usage: %prog (-b BEGIN -e END) | -a" parser = OptionParser(usage) parser.add_option('-b', '--begin', dest='begin', matavar="BEGIN", help="The ID in the database where fixing should begin (inclusive).") parser.add_option('-e', '--end', dest='end', metavar="END", help="The ID in the database where fi... |
doc.update_dates() | update_date(doc, simulate) | def main(): usage = "usage: %prog (-b BEGIN -e END) | -a" parser = OptionParser(usage) parser.add_option('-b', '--begin', dest='begin', matavar="BEGIN", help="The ID in the database where fixing should begin (inclusive).") parser.add_option('-e', '--end', dest='end', metavar="END", help="The ID in the database where fi... |
queryset = queryset_iterator(Document.objects.filter(documentUUID__gte=begin, documentUUID__lte=end) | queryset = queryset_iterator(Document.objects.filter(documentUUID__gte=begin, documentUUID__lte=end)) | def main(): usage = "usage: %prog (-b BEGIN -e END) | -a" parser = OptionParser(usage) parser.add_option('-b', '--begin', dest='begin', matavar="BEGIN", help="The ID in the database where fixing should begin (inclusive).") parser.add_option('-e', '--end', dest='end', metavar="END", help="The ID in the database where fi... |
update_date(doc) | update_date(doc, simulate) | def main(): usage = "usage: %prog (-b BEGIN -e END) | -a" parser = OptionParser(usage) parser.add_option('-b', '--begin', dest='begin', matavar="BEGIN", help="The ID in the database where fixing should begin (inclusive).") parser.add_option('-e', '--end', dest='end', metavar="END", help="The ID in the database where fi... |
i = 0 | i = len(caseLinks)-1 if verbosity >= 2: print str(i) | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
while i < len(caseLinks): | while i > 0: | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
i += 1 | i -= 1 | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
if dupCount == 3: | if dupCount == 8: | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
caseDate = regexII.search(junk).group(0).strip() caseNameShort = regexIII.search(junk).group(1).strip() | caseDate = cleanString(regexII.search(junk).group(0)) caseNameShort = regexIII.search(junk).group(1) | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
caseNumber = aTags[i].next.next.next.next.next.contents[0].strip()\ .replace(' ','') | caseNumber = aTags[i].next.next.next.next.next.contents[0] | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
elif "Published" in fileName: | elif 'p' in fileName: | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
.contents[0].replace(' ', ' ').strip() | .contents[0] caseDate = cleanString(caseDate) | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
.previous.previous.previous.previous.previous.strip() | .previous.previous.previous.previous.previous | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
caseDate = aTags[i].previous.previous.previous.contents[0].strip() | caseDate = aTags[i].previous.previous.previous.contents[0] caseDate = cleanString(caseDate) | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
doc.documentType = documentType | if documentType == 'U': doc.documentType = 'Unpublished' elif documentType == 'P': doc.documentType = 'Published' | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
.replace(' ', ' ').strip() | caseDate = cleanString(caseDate) | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
cleanDate = caseDates[i].text.strip() | cleanDate = cleanString(caseDates[i].text) | def scrapeCourt(courtID, result, verbosity, daemonmode): if verbosity >= 1: result += "NOW SCRAPING COURT: " + str(courtID) + "\n" if verbosity >= 2: print "NOW SCRAPING COURT: " + str(courtID) if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shal... |
results = queryset.set_options(mode="SPH_MATCH_EXTENDED2")\ .order_by('-dateFiled') | results = queryset.set_options(mode="SPH_MATCH_EXTENDED2") | def showResults(request): """Show the results for a query""" try: query = request.GET['q'] except: # if somebody is URL hacking at /search/results/ query = "" # this handles the alert creation form. if request.method == 'POST': from alert.userHandling.models import Alert # an alert has been created alertForm = Create... |
print obj | def items(self, obj): # Do a Sphinx query here. Return the first 20 results try: print obj queryset = Document.search.query(obj) results = queryset.set_options(mode="SPH_MATCH_EXTENDED2")\ .order_by('-dateFiled') except: results = [] return results | |
if userProfile.plaintextPreferred: txtTemplate = loader.get_template('emails/email.txt') c = Context({ 'hits': hits, }) email_text = txtTemplate.render(c) | send_mail( EMAIL_SUBJECT, email_text, EMAIL_SENDER, [userProfile.user.email], fail_silently=False) else: txtTemplate = loader.get_template('emails/email.txt') htmlTemplate = loader.get_template('emails/email.html') c = Context({ 'hits': hits, }) email_text = txtTemplate.render(c) html_text = htmlTemplate.render(c) | def emailer(rate): """This will load all the users each day/week/month, and send them emails.""" # remap the FREQUENCY variable from the model so the human keys relate back # to the indices rates = {} for r in FREQUENCY: rates[r[1].lower()] = r[0] RATE = rates[rate] # sphinx likes time in UnixTime format, which the be... |
send_mail( EMAIL_SUBJECT, email_text, EMAIL_SENDER, [userProfile.user.email], fail_silently=False) else: txtTemplate = loader.get_template('emails/email.txt') htmlTemplate = loader.get_template('emails/email.html') c = Context({ 'hits': hits, }) email_text = txtTemplate.render(c) html_text = htmlTemplate.render(c) | msg = EmailMultiAlternatives(EMAIL_SUBJECT, email_text, EMAIL_SENDER, [userProfile.user.email]) msg.attach_alternative(html_text, "text/html") | def emailer(rate): """This will load all the users each day/week/month, and send them emails.""" # remap the FREQUENCY variable from the model so the human keys relate back # to the indices rates = {} for r in FREQUENCY: rates[r[1].lower()] = r[0] RATE = rates[rate] # sphinx likes time in UnixTime format, which the be... |
msg = EmailMultiAlternatives(EMAIL_SUBJECT, email_text, EMAIL_SENDER, [userProfile.user.email]) msg.attach_alternative(html_text, "text/html") msg.send(fail_silently=False) | msg.send(fail_silently=False) | def emailer(rate): """This will load all the users each day/week/month, and send them emails.""" # remap the FREQUENCY variable from the model so the human keys relate back # to the indices rates = {} for r in FREQUENCY: rates[r[1].lower()] = r[0] RATE = rates[rate] # sphinx likes time in UnixTime format, which the be... |
myFile = downloadPDF(caseLink, caseName) | myFile = downloadPDF(caseLink) | def scrapeCourt(courtID, result): if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shall. """ url = "http://www.ca1.uscourts.gov/opinions/opinionrss.php" ct = Court.objects.get(courtUUID='ca1') req = urllib2.urlopen(url) tree = etree.parse(req) c... |
return render_to_response("profile/register_success.html", {'form': form, 'username': username, 'password': password, 'redirect_to': redirect_to}, RequestContext(request)) | return HttpResponseRedirect('/sign-in/?next=' + redirect_to) | def register(request): """allow only an anonymous user to register""" redirect_to = request.REQUEST.get('next', '') # security checks: # Light security check -- make sure redirect_to isn't garbage. if not redirect_to or ' ' in redirect_to: redirect_to = LOGIN_REDIRECT_URL # Heavier security check -- redirects to htt... |
i =+ 1 | def scrapeCourt(courtID, result): if (courtID == 1): """ PDFs are available from the first circuit if you go to their RSS feed. So go to their RSS feed we shall. """ url = "http://www.ca1.uscourts.gov/opinions/opinionrss.php" ct = Court.objects.get(courtUUID='ca1') req = urllib2.urlopen(url) tree = etree.parse(req) c... | |
return '%s.%s[%s]' % (cut.__module__, cut.__class__.__name__, slice_repr(self.slice)) | return '%s.%s[%s]' % (cut.__module__, cut.__class__.__name__, _slice_repr(self.slice)) | def __repr__(self): return '%s.%s[%s]' % (cut.__module__, cut.__class__.__name__, slice_repr(self.slice)) |
episodes = page.xpath("//div[@class='video']//div[@class='filmstrip_video']") | episodes = page.xpath("//div[@class='video']//div[@id='gallery_display']//div[@class='filmstrip_video']") | def ShowBrowser(sender, showUrl, showName, showThumb, pageNumber=1): dir = MediaContainer() if pageNumber > 1: pageUrl = showUrl + "?page=" + str(pageNumber) dir.title1 = showName dir.title2 = L('page') + ' ' + str(pageNumber) else: dir.title2 = showName pageUrl = showUrl page = XML.ElementFromURL(pageUrl, isHTML=Tr... |
for line in f: | for line in sorted(f): | def process(ifile, ofile): f = open(ifile, "r") plain_codes = set() # To prune duplicate lines... output = set() for line in f: line.rstrip("\n") fields = line.split("\t") # Skip codes without coordinates... if not len(fields[9]) or not len(fields[10]): continue code = fields[1] place = fields[2] lat = float(field... |
sys.stdout.write("USAGE: %s -h <hostname> -p <port> -r <rate> -f <postalcodes.txt>\n" % os.path.basename(sys.argv[0])) | sys.stdout.write("USAGE: %s [-h <hostname>] [-p <port>] [-r <rate>] -f <postalcodes.txt>\n" % os.path.basename(sys.argv[0])) | def print_usage(): sys.stdout.write("USAGE: %s -h <hostname> -p <port> -r <rate> -f <postalcodes.txt>\n" % os.path.basename(sys.argv[0])) |
if known_earlier: if OPTIONS.TO: if( not send_mail( "%s %s" % (url, state), "Site is %s at %s" % (state, datetime.datetime.now().ctime()) ) ): return config.set( url, "Time", int(time.time()) ) | if not known_earlier: if OPTIONS.TO: if( not send_mail( "%s %s" % (url, state), "Site is %s at %s" % (state, datetime.datetime.now().ctime()) ) ): return config.set( url, "Time", int(time.time()) ) | def report( config, url, down, known_earlier, last_change, state_pos ): """Report the state and eventual change""" if down: state = "down" color = Fore.RED space = "" else: state = "up" color = Fore.GREEN space = " " write( "%s%s%s%s%s" % (color, space, (state_pos-len(url))*" ", state, Fore.RESET)) if known_earlier... |
write( "Down" ) | write( "%sDown" % ((30-len(url))*" ")) | def check_urls(config, urls): """Will go through the url list and check if they are up""" for url in urls: if not config.has_section( url ): config.add_section( url ) try: down_earlier = config.getboolean( url, "Down" ) except ValueError: down_earlier = False except ConfigParser.NoOptionError: down_earlier = False ... |
write( "Up" ) | write( "%s Up" % ((30-len(url))*" ")) | def check_urls(config, urls): """Will go through the url list and check if they are up""" for url in urls: if not config.has_section( url ): config.add_section( url ) try: down_earlier = config.getboolean( url, "Down" ) except ValueError: down_earlier = False except ConfigParser.NoOptionError: down_earlier = False ... |
def __call__( self, eventdatafiles, nevents, *args): | def __call__( self, eventdatafiles_or_filename, nevents, *args): | def __call__( self, eventdatafiles, nevents, *args): '''histogram event data in the given list of event data files |
eventdatafiles: a list of event data files | eventdatafiles_or_filename: a list of event data files or one filename string | def __call__( self, eventdatafiles, nevents, *args): '''histogram event data in the given list of event data files |
tof = N.arange( 0, n, 1. ) | tof = N.arange( 0.5, n+0.4, 1. ) | def readHistogram( filename ): s = open(filename).read() import numpy as N I = N.fromstring( s, 'u4' ) n = len(I) tof = N.arange( 0, n, 1. ) import histogram as H Itof = H.histogram( 'I(tof)', [ ('tof', tof, tofunit), ], data = I, errors = I ) return Itof |
IMAGE_UUID = result | self.IMAGE_UUID = result | def test_06computerCreateImageDirectory(self): """ Create a directory to store a Pulse 2 image """ result = SERVER.computerCreateImageDirectory('00:11:22:33:44:ff') self.assertTrue(isUUID(result)) self.assertTrue(os.path.exists('/var/lib/pulse2/imaging/masters/%s' % result)) IMAGE_UUID = result |
os.system('tar xzf ../data/pulse2-image-sample.tar.gz -C /var/lib/pulse2/imaging/masters/' + IMAGE_UUID) result = SERVER.imageDone('00:11:22:33:44:ff', IMAGE_UUID) | os.system('tar xzf ../data/pulse2-image-sample.tar.gz -C /var/lib/pulse2/imaging/masters/' + self.IMAGE_UUID) result = SERVER.imageDone('00:11:22:33:44:ff', self.IMAGE_UUID) | def test_08imageDone(self): """ Tell that the image is done """ # Put a sample image os.system('tar xzf ../data/pulse2-image-sample.tar.gz -C /var/lib/pulse2/imaging/masters/' + IMAGE_UUID) result = SERVER.imageDone('00:11:22:33:44:ff', IMAGE_UUID) self.assertTrue(result) |
result = SERVER.imagingServerISOCreate(IMAGE_UUID, 650 * 1024 * 1024, title) | result = SERVER.imagingServerISOCreate(self.IMAGE_UUID, 650 * 1024 * 1024, title) | def test_09generateISO(self): """ Check ISO generation """ title = "Image ISO" result = SERVER.imagingServerISOCreate(IMAGE_UUID, 650 * 1024 * 1024, title) self.assertTrue(result) # Check that we have an ISO file ret = False for _ in range(10): if os.path.exists(os.path.join('/var/lib/pulse2/imaging/isos', title + '-1.... |
result = SERVER.computerUnregister('UUID2', [IMAGE_UUID], True) | result = SERVER.computerUnregister('UUID2', [self.IMAGE_UUID], True) | def test_10computerUnregister(self): """ Check computer archival """ result = SERVER.computerUnregister('UUID4', [], False) self.assertTrue(result) # Wait for the archival background process to be done sleep(5) # No archival done self.assertFalse(os.path.exists('/var/lib/pulse2/imaging/archives/UUID4-1')) # Computer di... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.