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

Add apk url and version code for latest release #6

Merged
merged 4 commits into from
Jul 4, 2018

Conversation

TobiGr
Copy link
Member

@TobiGr TobiGr commented Jul 4, 2018

This should be everything we need for TeamNewPipe/NewPipe#1520

I changed the structure a bit to handle the different release platforms F-Droid and GitHub better.

{
  "stats": {
    "stargazers": 3807,
    "watchers": 216,
    "forks": 600,
    "contributors": 243,
    "translations": 53
  },
  "flavors": {
    "stable": {
      "f-droid": {
        "version": "v0.13.5",
        "version_code": 64,
        "apk": "https://f-droid.org/repo/org.schabi.newpipe_64.apk"
      },
      "github": {
        "version": "v0.13.5",
        "apk": "https://github.com/TeamNewPipe/NewPipe/releases/download/v0.13.5/NewPipe-v0.13.5.apk"
      }
    }
  }
}

@TobiGr TobiGr changed the title Add apk url for latest GitHub release Add apk url and version code for latest release Jul 4, 2018
api.py Outdated
}

repo = json.loads(repo_data)

# scrap latest GitHub version and apk from website
elem = html.fromstring(release_github_data)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheAssassin Do you have any idea how I can reduce the redundancy here? I didn't find a good way to do so.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of redundancy are you talking about specifically?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the same structure for getting the GitHub version, apk and the contributors count:
Get HTML, use cssselect to filter the HTML, check if the we get the a valid number of results, get the first result and modify it.

Unfortunately I couldn't move this to a new method because I failed to execute the steps in the try blocks in a good way. My initial idea was to return tags[0]:

        def scrape_data_from_html(data, selector: str):
            elem = html.fromstring(data)
            tags = elem.cssselect(selector)
            if len(tags) < 1:
                return -1
            else:
                try:
                    return tags[0]
                except:
                    return -1

But than I realised that I'd needed another try and catch to handle the possible exceptions which can be thrown by tags[0].get('href'), tags[0].text and int(tags[0].text):

contributors_result = scrape_data_from_html(contributors_data, ".numbers-summary a[href$=contributors] .num")
try:
    contributors_count = int(contributors_result.text)
except:
    contributors_count = -1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am okay with this as it is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good,

@@ -166,7 +192,13 @@ def assemble_release_data(data: str):
"translations": int(translations["count"]),
},
"flavors": {
"stable": assemble_release_data(stable_data),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to split this up into "github": {"stable": {...}, ...} and "f-droid": {"stable": {...}, ...} instead? GitHub names releases differently, i.e. there's releases and pre-releases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

api.py Outdated
except:
release_github_version = -1

# scrap contributors from website
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's "scrape" ("extract"), not "scrap" ("dispose", "throw away").

Copy link
Member

@TheAssassin TheAssassin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be merged, @TobiGr.

@TobiGr
Copy link
Member Author

TobiGr commented Jul 4, 2018

@TheAssassin Feel free to merge. I can't do it.

@TheAssassin
Copy link
Member

@TobiGr I was already working on some solution for this. I added a team, and I'm granting this team permissions for all relevant NewPipe repositories. Please check if you can merge here now, too.

@TobiGr TobiGr merged commit 1bca377 into TeamNewPipe:master Jul 4, 2018
@TobiGr
Copy link
Member Author

TobiGr commented Jul 4, 2018

I added a team, and I'm granting this team permissions for all relevant NewPipe repositories.

That is a good idea!

@TheAssassin
Copy link
Member

Deployment in progress.

@TobiGr
Copy link
Member Author

TobiGr commented Jul 4, 2018

Thanks

@TobiGr TobiGr deleted the apk-url branch July 5, 2018 19:55
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

Successfully merging this pull request may close these issues.

2 participants