I've been trying to get the output from the steam API to display in my django app.
My goal is to create a "portfolio" of games that I own for a project - using the information in the Steam API. I'm fairly new to Django, but know enough to be dangerous. Any help would be greatly appreciated, as I have been banging against this for a week...
My question is, how does one pull specific items from the json and display the data correctly inside of the template? I cannot seem to loacte a tutorial that fits the schema of the output from this API. - any help (and a brief explanation maybe) would be greatly appreciated.
For example, how can I capture the minimum system requirements from the API and display them in a div on my page?
This is my views.py:
def index(request):
response = requests.get('https://store.steampowered.com/api/appdetails/?appids=218620').json()
return render(request, 'index.html', {'response': response})
While it actually returns data, you'll notice that the data is littered with weird characters and such.
output:
</ul>', 'short_description': 'PAYDAY 2 is an action-packed, four-player co-op shooter that once again lets gamers don the masks of the original PAYDAY crew - Dallas, Hoxton, Wolf and Chains - as they descend on Washington DC for an epic crime spree.', 'supported_languages': 'English<strong>*</strong>, German, French, Italian, Spanish - Spain, Dutch, Russian, Japanese, Simplified Chinese, Spanish - Latin America, Korean<br><strong>*</strong>languages with full audio support', 'header_image': 'https://cdn.akamai.steamstatic.com/steam/apps/218620/header.jpg?t=1646834144', 'website': 'http://www.paydaythegame.com/', 'pc_requirements': {'minimum': '<strong>Minimum:</strong><br><ul class="bb_ul"><li><strong>OS:</strong>Windows 7<br>\t</li><li><strong>Processor:</strong>2 GHz Intel Dual Core Processor<br>\t</li><li><strong>Memory:</strong>4 GB RAM<br>\t</li><li><strong>Graphics:</strong>Nvidia & AMD (512MB VRAM)<br>\t</li><li><strong>DirectX®:</strong>9.0c<br>\t</li><li><strong>Storage:</strong>83 GB available space<br>\t</li><li><strong>Sound:</strong>DirectX 9.0c compatible</li></ul>', 'recommended': '<strong>Recommended
Here is my index.html:
{% extends 'base.html' %}
{% block content %}
{{response}}
{% endblock %}
if you add a 'safe' tag to the django template like this:
{% extends 'base.html' %}
{% block content %}
{{ response | safe }}
{% endblock %}
It cleans up the displayed output considerably, but still shows a bunch of weird characters in weird places - eg.
', 'short_description': 'PAYDAY 2 is an action-packed, four-player co-op shooter that once again lets gamers don the masks of the original PAYDAY crew - Dallas, Hoxton, Wolf and Chains - as they descend on Washington DC for an epic crime spree.', 'supported_languages': 'English\*, German, French, Italian, Spanish - Spain, Dutch, Russian, Japanese, Simplified Chinese, Spanish - Latin America, Korean *languages with full audio support', 'header_image': 'https://cdn.akamai.steamstatic.com/steam/apps/218620/header.jpg?t=1646834144', 'website': 'http://www.paydaythegame.com/', 'pc_requirements': {'minimum': 'Minimum:OS:Windows 7 \t Processor:2 GHz Intel Dual Core Processor
Related
I apologise before for a long explanation - I have a hard time explaining it to myself.
I run Shopware 6 locally and using the development template. I needed to remove the product number from the product detail page. So, I override the twig template "buy-widget.html.twig":
{% sw_extends '#Storefront/storefront/page/product-detail/buy-widget.html.twig' %}
{% block page_product_detail_ordernumber_container %}
{% endblock %}
Works as expected - if I have not change the layout template for the product, but using the Shopware default.
But, when I change the layout to a custom layout (the only difference is that the image thumbs is bellow the main image) the product number is back?!
Checking with the Symfony Profiler, I can see that it's now another twig template (from a folder "component/.." responsible for displaying the product number.
Question: Am I correct to assume that I should extend the twig template from this component folder if I'm using a custom layout? I have not find anything in the docs about these "small" details. And if one need to be sure that a custom theme works in every case, you must make the changes (using sw_extends) in two files?
/ Magnus
Is there a way to automatically output the logo of a sales channel in the documents (invoice, delivery bill, etc.) without having to create a separate document for each sales channel?
Thanks for your help :-)
Unfortunately, I have not found an approach so far.
I think it currently isn't possible to differentiate between sales channels with the document settings in the administration.
You could create a media custom field for the sales channel, upload the logo there and then use the custom field in the document template.
Go to Settings > System > Custom Fields
Add a new set and assign it to Sales Channels
Within the new set create a new custom field
As type choose Media and think of a unique technical name
In the sidebar to the left go to the sales channel you want to upload a logo for
Scroll down to the custom fields of the sales channel and upload the logo with the new media custom field
Save the sales channel
Then you'll need a plugin to extend the document template. Within your plugin create the template extension e.g. at {pluginRoot}/src/Resources/views/documents/base.html.twig
with the content:
{% sw_extends '#Framework/documents/base.html.twig' %}
{% block document_header %}
{% if context.salesChannel.customFields.custom_test_media is defined %}
{% set media = searchMedia([context.salesChannel.customFields.custom_test_media], context.context) %}
{# #var item \Shopware\Core\Content\Media\MediaEntity #}
{% for item in media %}
<img src="{{ item.url }}" class="logo"/>
{% endfor %}
{% endif %}
{% endblock %}
with custom_test_media being the technical name of the media custom field you created earlier.
Here is a video how to change Shopwares Document Logos the easy way using the WYSIWYG Document Editor:
https://youtu.be/fGBMDmVMPvA?t=162
The easiest way to change your documents is by customizing them with the WYSIWYG Document Editor. The live preview will save you a lot of time and money in comparison to going back and forth 1000 times between making adjustments in your Twig Templates and generating new PDFs for testing.
Check it out:
https://store.shopware.com/appli81810362453/wysiwyg-dokumenten-editor-pdf-rechnungen-lieferscheine-gutschriften-stornos-designen.html
I am the developer, which created the WYSIWYG Document Editor Shopware 6 App. Feel free to ask me any questions about the App. I am happy to help you.
{%- -%} is a whitespace delimiter in Shopify liquid. I am trying to edit the default emmet function in PhpStorm's twig language to instead output this rather than the default {% %}.
Also looking to change the default twig comment style from {# #} to {% comment %}{% endcomment %}
As this is specific to Liquid, I don't have access to editing the delimiters, such as is the case using something like Vue
Sadly, Twig support plugin does not allow customizing the lexer syntax yet.
https://youtrack.jetbrains.com/issue/WI-15739 -- watch this ticket (star/vote/comment) to get notified on any progress.
{% comment %}{% endcomment %} -- similar story (you cannot customize what symbols/tags are used for comments.
Proper Liquid templates support is tracked in the following ticket: https://youtrack.jetbrains.com/issue/RUBY-7210 -- star/vote/comment it to get notified on any progress. Hopefully devs can bring some updates in one of the next major versions (at very least there was some activity in this ticket in terms of expected Liquid support/functionality).
...default emmet function in PhpStorm's twig language...
Commenting functionality is not provided by Emmet by any means -- it's implemented by plugin specifically for this language (IDE has standard "Block Comment" and "Line Comment" actions and plugins for corresponding language just provides how the commenting should be handled.
If you want to use some emmet-like abbreviation that will expand into {% comment %}some text here{% endcomment %} or alike then you are welcome to create custom Live Template and use it even right now (e.g. as a "Surround with..." kind of template). You can create one at Settings (Preferences on macOS) | Editor | Live Templates.
https://www.jetbrains.com/help/phpstorm/using-live-templates.html
I am trying to get the news article from this link. My code is :
def get_news_details(news_url):
source = requests.get(news_url)
plain_text = source.text
soup = BeautifulSoup(plain_text, "html.parser")
content = soup.findAll('div', {'class' : 'big-img-box'})
print(content[0].findAll('p'))
The result shows :
[<p></p>, <p></p>, <p></p>, <p></p>, <p></p>, <p></p>]
And the value of content is :
<div class="big-img-box">
<div class="left-imgs">
<figure>
<img alt="iOS developer hints possibility of 4K Apple TV" class="img-responsive" src="http://www.aninews.in/contentimages/detail/appletv.jpg"/>
<figcaption><span class="heading-inner-span"></span></figcaption>
</figure>
<div class="mb10"></div>
</div>
<p></p> New York [USA], August 6 <a class="highlights" href="http://aninews.in/" target="_blank">(ANI)</a>: The latest designs from Apple's HomePod firmware revealed that the tech giant is hinting the launch of a <span class="highlights"> 4K Apple TV</span> with high dynamic range (HDR) support for both <span class="highlights"> HDR10 </span> and <span class="highlights"> Dolby Vision</span>.<p></p> While the current range of Apple's TV set-top box is incompatible to 4K technology, <span class="highlights">iOS</span> developer <span class="highlights"> Guilherme Rambo</span> revealed that the company is hinting an adoption of the ultra high-definition format, reports <span class="highlights">The Verge</span>.<p></p> Reports of the new range of Apple TV have surfaced time and again over the past few months, starting February this year.<p></p> It is said that implementing the HDR and 4K content will prove to b beneficial for the company, rather than a simpler resolution, since popular online movie and television platforms like <span class="highlights"> Netflix</span> and <span class="highlights"> Amazon</span> support the two high-definition formats.<p></p> Last month, iTunes started listing movies as supporting 4K and <span class="highlights"> HDR</span> in users' purchase histories, thus providing more thrust to the speculations of the 4K <span class="highlights"> Apple</span> TV. <a class="highlights" href="http://aninews.in/" target="_blank">(ANI)</a><p></p>
</div>
I can get a somewhat clumsy version of the article by content[0].text but I cannot format it.
While inspecting the webpage in chrome, the article seems to be written inside <p>article_text</p> tags. Whereas in content, it appears as <p></p>article_text tags. If the former version is present in soup, I can get my desired output. What should be done ?
It depends what you mean by formatting. You can make it 'tidier' in fairly simple ways.
>>> import bs4
>>> import requests
>>> page = requests.get('http://www.aninews.in/newsdetail-Nw/MzI4NDIy/ios-developer-hints-possibility-of-4k-apple-tv.html').content
>>> soup = bs4.BeautifulSoup(page, 'lxml')
>>> big_img_box = soup.select('.big-img-box')
Get all the text and strip away white space.
>>> big_img_box[0].text.strip()
"New York [USA], August 6 (ANI): The latest designs from Apple's HomePod firmware revealed that the tech giant is hinting the launch of a 4K Apple TV with high dynamic range (HDR) support for both HDR10 and Dolby Vision. While the current range of Apple's TV set-top box is incompatible to 4K technology, iOS developer Guilherme Rambo revealed that the company is hinting an adoption of the ultra high-definition format, reports The Verge. Reports of the new range of Apple TV have surfaced time and again over the past few months, starting February this year. It is said that implementing the HDR and 4K content will prove to b beneficial for the company, rather than a simpler resolution, since popular online movie and television platforms like Netflix and Amazon support the two high-definition formats. Last month, iTunes started listing movies as supporting 4K and HDR in users' purchase histories, thus providing more thrust to the speculations of the 4K Apple TV. (ANI)"
Go beyond this and remove longer strings of interior white space.
>>> import re
>>> re.sub(r'\s{2,}', ' ', big_img_box[0].text.strip())
"New York [USA], August 6 (ANI): The latest designs from Apple's HomePod firmware revealed that the tech giant is hinting the launch of a 4K Apple TV with high dynamic range (HDR) support for both HDR10 and Dolby Vision. While the current range of Apple's TV set-top box is incompatible to 4K technology, iOS developer Guilherme Rambo revealed that the company is hinting an adoption of the ultra high-definition format, reports The Verge. Reports of the new range of Apple TV have surfaced time and again over the past few months, starting February this year. It is said that implementing the HDR and 4K content will prove to b beneficial for the company, rather than a simpler resolution, since popular online movie and television platforms like Netflix and Amazon support the two high-definition formats. Last month, iTunes started listing movies as supporting 4K and HDR in users' purchase histories, thus providing more thrust to the speculations of the 4K Apple TV. (ANI)"
I have a site, using EE 1.73, set up with various weblogs and am trying to pass the correct info to the html tag.
I have added the following to the tag -
{if segment_3}
<title>{site_name} | {exp:weblog:entries weblog=“features|reviews|tutorials|catchreports|news|species|rigs|videos” limit=“1” disable=“categories|custom_fields|member_data|pagination|trackbacks”
}{weblog} | {title}{/exp:weblog:entries}</title>
{if:else}
<title>{site_name}</title>
{/if}
And this correctly give the title for the home page as - Planet Sea Fishing Digital Magazine
The actual article title is fine too with http://www.planetseafishing.com/reviews/read/the-reel-service-centre/ being rendered correctly as Planet Sea Fishing Digital Magazine | Reviews | The Reel Service Centre
My problem, as a beginner, is that I can’t figure out how to get the page title for the actual weblog to render correctly ie for http://www.planetseafishing.com/reviews/ to show as Planet Sea Fishing Digital Magazine | Reviews
I presume that it has something to do with using the fact that segment_3 is blank in this case but no matter what I try I can’t get the title to render properly.
Any suggestions?
Thanks
David
Are you using one template to serve the site index, the weblog listing and the weblog entries? If so you could try nested your conditionals like this:
{if segment_3}
<title>{site_name} | {exp:weblog:entries weblog="features|reviews|tutorials|catchreports|news|species|rigs|videos" limit="1" disable="categories|custom_fields|member_data|pagination|trackbacks"
}{weblog} | {title}{/exp:weblog:entries}</title>
{if:else}
{if segment_2}
<title>{site_name} | {exp:weblog:entries weblog="features|reviews|tutorials|catchreports|news|species|rigs|videos" limit="1" disable="categories|custom_fields|member_data|pagination|trackbacks"}{weblog}{/exp:weblog:entries}</title>
{if:else}
<title>{site_name}</title>
{/if}
{/if}
I don't quite understand your structure tho. Based on your url it looks like "reviews" is a template group as well as a weblog. Does each weblog have it's own template group?
I believe that in EE 1.x, the title for the weblog can be accessed via the EE variable {blog_title}, which is different than the {title} variable used to access the entry title.
Try this code, without any conditionals. By the inclusion of the "require entry=yes" parameter, hopefully this code will only show your expanded blog and page titles when the result of your {exp:weblog:entries} call actually returns an entry - i.e., when there's dynamic data to present via the URI. Otherwise, it shouldn't display anything.
Hopefully I'm not missing your intent!
<title>{site_name}{exp:weblog:entries weblog=“features|reviews|tutorials|catchreports|news|species|rigs|videos” limit=“1” disable=“categories|custom_fields|member_data|pagination|trackbacks” require_entry="yes"
} | {blog_title} | {title}{/exp:weblog:entries}</title>