Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relatedBills.py #4

Closed
adamwjo opened this issue Aug 25, 2020 · 4 comments
Closed

relatedBills.py #4

adamwjo opened this issue Aug 25, 2020 · 4 comments

Comments

@adamwjo
Copy link
Contributor

adamwjo commented Aug 25, 2020

Running into some hiccups thought I would discuss here:

I am creating a file called relatedBills.py to do the following:

  • Load the titlesIndex file
def loadTitlesIndex(titleIndexPath=PATH_TO_TITLES_INDEX, zip=True):
    titlesIndex = {}
    if zip:
        try:
            with gzip.open(titleIndexPath + '.gz', 'rt', encoding='utf-8') as zipfile:
                titlesIndex = json.load(zipfile)
        except:
            raise Exception('No file at' + titleIndexPath + '.gz')
    else:
        try:
            with open(titleIndexPath, 'r') as f:
                titlesIndex = json.load(f)
        except:
            raise Exception('No file at' + titleIndexPath + '.gz')
    return titlesIndex
  • Loop over the data in the titlesIndex file and grab the list of billnumbers for each title
  • Loop over each list of bill numbers and return a dictionary containing a billnumber key, and list containing all the billsnumbers that share the same title
def getSameTitles():
    titlesIndex = loadTitlesIndex()
    newIndex = {}
    for key, value in titlesIndex.items():
        bills = value
        for bill in bills:
            if newIndex.get(bill):
                newIndex[bill].append(bill)
            else:
                newIndex[bill] = bill

So far I'm getting a string attribute error leading me to believe that the value I get from newIndex[bill] is not what I'm assuming it is, still working on it but would appreciate any input'

@adamwjo
Copy link
Contributor Author

adamwjo commented Aug 25, 2020

Nevemind I think I found it in my else statement newIndex[bill] = [bill]

@adamwjo
Copy link
Contributor Author

adamwjo commented Aug 25, 2020

I think the next thing I have to do is reduce the lists in my newIndex dictionary to remove duplicate values

@aih
Copy link
Collaborator

aih commented Aug 25, 2020

Note: I reformatted the code. You can use three ` marks with the type of code ('Python' here).

@aih
Copy link
Collaborator

aih commented Aug 26, 2020

Closing this discussion issue. I'll open a separate issue for the feature that is being built.

@aih aih closed this as completed Aug 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants