python – Effective algorithm for retrieving data

I'm getting some data with bs4 and want to know why the access speed slows down as the program progresses.

I use thread and I know that threading is not that fast because of GIL.

My problem is that my program is gradually slowing down.
However, if the number of words exceeds 300, it will be much slower than the number of words at about 100 words.

GIL causes that?

(Multiprocessing can solve the GIL problem, but I may want to find other causes.)

What is the better web scraping code that can be downloaded immediately?

Thank you very much.

import os,gc,queue
import requests, bs4
from threading import Thread, BoundedSemaphore
class add_line:
    def __init__(self,semaphore,q):
        self.q = q # queue
        self.semaphore = semaphore

    def put_queue(self,li): #insert 
        self.q.put(li)

    def fetch_word(self,w_list):
        fetched_text = ""# targeted text
        path = "https://ejje.weblio.jp/content/"+ w_list(1)
        res = requests.get(path)
        res.raise_for_status()
        no_starch_soup = bs4.BeautifulSoup(res.text)
        fetched_text = no_starch_soup.select('.conjugateRowR > table > tr > td')
        if len(fetched_text)== 0: #if get nothing
            fetched_text = no_starch_soup.select('.conjugateRowR > a')
            if len(fetched_text) ==0:# if get nothing too
                self.put_queue(w_list)# return original conjurate
            else :
                li_ = list(map(lambda x:x.contents(0), fetched_text))
                li_.insert(0,w_list(0))
                self.put_queue(li_)
        else:
            li_=list(map(lambda x:x.contents(0), fetched_text))
            li_.insert(0,w_list(0))
            self.put_queue(li_)
        gc.collect()
        self.semaphore.release() 
if __name__ == "__main__": 
    # creating thread
    maxconnections = 5
    path = "./target_index1900.txt"
    """
    the part of this text data is below(the number of words is over 1000)

    510 abandon
    510 abandonment
    1807 abide
    1318 abolish
    1318 abolition
    1167 abortion
    1167 abortive
    1096 abound
    1683 abrupt
    1683 abruptly
    1199 absolute
    1199 absolutely
    507 absorb
    507 absorption
    899 abstract
    899 abstraction

    """
    #set semaphore 
    pool_sema = BoundedSemaphore(value=maxconnections)
    q = queue.Queue()# put word  in queue 
    al = add_line(pool_sema,q)
    path_w = "./threading_test_result.txt"
    with open(path) as f:
        while True:
            lines = f.readline()
            if not lines:
                break
            pool_sema.acquire()
            Thread(target=al.fetch_word, args=(lines.split(" "),)).start()
    with open(path_w, mode='a') as f:
        while not q.empty():
            for x in q.get():
                f.write(x)
                f.write(" ")
            f.write("n")
        f.close()
        gc.collect()
    print("Done!")

magento2 – To implement a method for retrieving the configuration value in the store and in the default scope: Magento 2

In Magento 1 a call to Mage::getStoreConfig('section/group/field') could retrieve a configuration of the current memory. For example, if we called it from a front panel, it retrieved the configuration value of the current memory, and when we called it from an admin block, it retrieved the value of admin memory (id=0).

Is it still possible in Magento 2 to have such a method?

For example, I created a helper with the following content:

namespace VendorNameModuleNameHelper;

use MagentoStoreModelScopeInterface;
use MagentoFrameworkAppHelperAbstractHelper;
use MagentoFrameworkAppHelperContext;

class Config extends AbstractHelper
{
    const XML_PATH_FEATURE_ENABLED = 'section/group/my_feature_enabled';

    /**
     * Get enabled config
     * @param int|null $storeId
     * @return mixed
     */
    public function isEnabled($storeId = null)
    {     
            return $this->scopeConfig->getValue(
                self::XML_PATH_FEATURE_ENABLED,
                ScopeInterface::SCOPE_STORE,
                $storeId
            );
        }
    }
}

For information: In my test environment, I only have one store view.
My core_config_data Table looks like this:

scope   |  scope_id |                path               |    value 
default |    0      | section/group/my_feature_enabled  |      0
stores  |    1      | section/group/my_feature_enabled  |      1

When I call it from the frontend area, it works as expected (returns) 1). But when I call it from the administrator, it does not return the default administrator value: it is returned 1 to …

If I change ScopeInterface::SCOPE_STORE by default by doing isEnabled Method, it always returns the default value (admin value), but it does not return the good front-end value …

So, what is the Magento 2 method to achieve the same result as the Magento 1? Mage::getStoreConfig Method?

Infopath – Sharepoint 2010 Approval Workflow Form – Retrieving Data from the Comments Box

I am using Sharepoint 2013 OP with SPD 2013.

I have created a Sharepoint 2010 Approval workflow with the default workflow. If the user approves the item, a comment field is preinstalled.

How do I drag the comments entered by the approver into the field and add them to the email sent via the Approved Email Initiator (requester) action?

Thank you very much

magento2.3 – Retrieving the salable quantity via SQL

I'm trying to get all the inventory of a product for debugging via SQL.
The part I am not 100% on is the salable quantity.

I have the following:

SELECT t1.`quantity` + SUM(t2.`quantity`) salable_quantity
FROM `inventory_source_item` t1
JOIN `inventory_reservation` t2
ON t1.`sku` = t2.`sku` AND t1.`status` = 1
WHERE t1.`sku` = 'MY-PROD-SKU'

This works mostly and sometimes returns NULL.

I had hoped that a Magento user would write something similar and make improvements to this query. Many thanks

Retrieving javax.servlet.ServletException: java.lang.IllegalStateException: No resource under MyClassName / webServiceContext

Deploying an application in Jetty Server with Open appleJdk will be below the exception.

In Java 8 it worked perfectly.

javax.servlet.ServletException: java.lang.IllegalStateException: No resource under MyClassName / webServiceContext
at org.eclipse.jetty.servlet.ServletContextHandler $ Context.createServlet (ServletContextHandler.java:1297)
at org.eclipse.jetty.servlet.ServletHolder.newInstance (ServletHolder.java:1270)
at org.eclipse.jetty.servlet.ServletHolder.initServlet (ServletHolder.java:633)
at org.eclipse.jetty.servlet.ServletHolder.initialize (ServletHolder.java:421)
at org.eclipse.jetty.servlet.ServletHandler.lambda $ initialize $ 0 (ServletHandler.java:746)
at java.base / java.util.stream.SortedOps $ SizedRefSortingSink.end (SortedOps.java:357)
at java.base / java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:485)
at java.base / java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:474)
at java.base / java.util.stream.StreamSpliterators $ WrappingSpliterator.forEachRemaining (StreamSpliterators.java:312)
at java.base / java.util.stream.Streams $ ConcatSpliterator.forEachRemaining (Streams.java:735)
at java.base / java.util.stream.Streams $ ConcatSpliterator.forEachRemaining (Streams.java:734)
at java.base / java.util.stream.ReferencePipeline $ Head.forEach (ReferencePipeline.java:658)
at org.eclipse.jetty.servlet.ServletHandler.initialize (ServletHandler.java:739)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext (ServletContextHandler.java:361)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp (WebAppContext.java:1443)
at org.eclipse.jetty.webapp.WebAppContext.startContext (WebAppContext.java:1407)
at org.eclipse.jetty.server.handler.ContextHandler.doStart (ContextHandler.java:821)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart (ServletContextHandler.java:276)
at org.eclipse.jetty.webapp.WebAppContext.doStart (WebAppContext.java:524)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:72)
at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding (defaultStarter.java:46)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings (AppLifeCycle.java:188)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal (DeploymentManager.java:513)
at org.eclipse.jetty.deploy.DeploymentManager.addApp (DeploymentManager.java:154)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileChanged (ScanningAppProvider.java:189)
at org.eclipse.jetty.deploy.providers.WebAppProvider.fileChanged (WebAppProvider.java:395)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider $ 1.fileChanged (ScanningAppProvider.java:72)
at org.eclipse.jetty.util.Scanner.reportChange (Scanner.java:676)
at org.eclipse.jetty.util.Scanner.reportDifferences (Scanner.java:541)
at org.eclipse.jetty.util.Scanner.scan (Scanner.java:402)
at org.eclipse.jetty.util.Scanner $ 1.run (Scanner.java:336)
at java.base / java.util.TimerThread.mainLoop (Timer.java:556)
at java.base / java.util.TimerThread.run (Timer.java:506)
Caused by:
java.lang.IllegalStateException: No resource under MyClassName / webServiceContext
at org.eclipse.jetty.annotations.ResourceAnnotationHandler.handleMethod (ResourceAnnotationHandler.java:351)
at org.eclipse.jetty.annotations.ResourceAnnotationHandler.doHandle (ResourceAnnotationHandler.java:74)
at org.eclipse.jetty.annotations.AnnotationIntrospector $ AbstractIntrospectableAnnotationHandler.handle (AnnotationIntrospector.java:71)
at org.eclipse.jetty.annotations.AnnotationIntrospector.introspect (AnnotationIntrospector.java:106)
at org.eclipse.jetty.annotations.AnnotationDecorator.introspect (AnnotationDecorator.java:62)
at org.eclipse.jetty.annotations.AnnotationDecorator.decorate (AnnotationDecorator.java:68)
at org.eclipse.jetty.util.DecoratedObjectFactory.decorate (DecoratedObjectFactory.java:85)
at org.eclipse.jetty.servlet.ServletContextHandler $ Context.createServlet (ServletContextHandler.java:1292)
at org.eclipse.jetty.servlet.ServletHolder.newInstance (ServletHolder.java:1270)
at org.eclipse.jetty.servlet.ServletHolder.initServlet (ServletHolder.java:633)
at org.eclipse.jetty.servlet.ServletHolder.initialize (ServletHolder.java:421)
at org.eclipse.jetty.servlet.ServletHandler.lambda $ initialize $ 0 (ServletHandler.java:746)
at java.base / java.util.stream.SortedOps $ SizedRefSortingSink.end (SortedOps.java:357)
at java.base / java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:485)
at java.base / java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:474)
at java.base / java.util.stream.StreamSpliterators $ WrappingSpliterator.forEachRemaining (StreamSpliterators.java:312)
at java.base / java.util.stream.Streams $ ConcatSpliterator.forEachRemaining (Streams.java:735)
at java.base / java.util.stream.Streams $ ConcatSpliterator.forEachRemaining (Streams.java:734)
at java.base / java.util.stream.ReferencePipeline $ Head.forEach (ReferencePipeline.java:658)
at org.eclipse.jetty.servlet.ServletHandler.initialize (ServletHandler.java:739)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext (ServletContextHandler.java:361)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp (WebAppContext.java:1443)
at org.eclipse.jetty.webapp.WebAppContext.startContext (WebAppContext.java:1407)
at org.eclipse.jetty.server.handler.ContextHandler.doStart (ContextHandler.java:821)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart (ServletContextHandler.java:276)
at org.eclipse.jetty.webapp.WebAppContext.doStart (WebAppContext.java:524)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:72)
at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding (defaultStarter.java:46)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings (AppLifeCycle.java:188)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal (DeploymentManager.java:513)
at org.eclipse.jetty.deploy.DeploymentManager.addApp (DeploymentManager.java:154)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileChanged (ScanningAppProvider.java:189)
at org.eclipse.jetty.deploy.providers.WebAppProvider.fileChanged (WebAppProvider.java:395)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider $ 1.fileChanged (ScanningAppProvider.java:72)
at org.eclipse.jetty.util.Scanner.reportChange (Scanner.java:676)
at org.eclipse.jetty.util.Scanner.reportDifferences (Scanner.java:541)
at org.eclipse.jetty.util.Scanner.scan (Scanner.java:402)
at org.eclipse.jetty.util.Scanner $ 1.run (Scanner.java:336)
at java.base / java.util.TimerThread.mainLoop (Timer.java:556)

MyClass.java is a web service

@javax.jws.WebService (
serviceName = "MyInterface",
name = "1HttpPort",
targetNamespace = "xxxxxx",
endpointInterface = "xxxxxxxxx")

public senior class MyClass extends HttpServlet implemented MyInterface {

@javax.annotation.resource
private WebServiceContext context;

public CustomResponse someMNethod(final SomeRequestsomeRequest) throws Exception { 

    try {

            final HttpServletRequest request = (HttpServletRequest)ctx.get(MessageContext.SERVLET_REQUEST);
            //BusinessLogic

       return printResponse;

      } catch (Exception ex) {
        }

}

}

JS or TS – retrieving the keys of an interface

Suppose I have an interface like:

export interface Album{
    id: string,
    code: string,
    title: string,
    description: string,
    publisher: string,
}

(Actually, it's pretty long – I just simplified it here).
Anyway, I want to create an object like:

const columnSpecs = {
        "id": {  "title": "ID", "width": 300 },
        "code": { "title": "Code", "width": 150 },
        "title": { "title": "Title", "width": 150 },
        "description": { "title": "Description", "width": 150 },
        "publisher": { "title": "Publisher", "width": 150 },
};

I'm writing now columnSpecs itself, but if this interface changes, I need to update the object columnSpecs,

Is there a way to extract the interface key so that I can iterate over the interface I used to create the object myself?

Many thanks.

applescript – osa script for retrieving user input with if condition

I want to run an osa script to run it in a self-service application.

First, this line must be displayed:

osascript 'tell app "System Events" to display dialog "Save and close all your files and application"'
once user pressed ok (if condidion need to use here)
if(user input is ok); then
some commands need to execute
else
display as terminated

These should run in jam in self-service

(apple script(scpt) file not executing in self service, so bash script required)

PHP error while retrieving data from the MySQL database

This question already has an answer here:

Good morning guys, okay? I have a problem below. I hosted my PHP site on a server that contains the DNS and the main suffix of the network, so the site can only be accessed internally within the company. On my PC running WampServer, the application works normally, but after I went to the server and replicated the database with the same password, DB name, etc., I encountered this error. Can someone tell me why?

NOTE: The error also occurs when I enter which site is hosted via the server's local host or via the direct link. I did connect tests directly in MySQL WorkBench and it worked normally.

Enter image description here

My connection is as follows:

 connect_error){
    die("Conex√£o falhou: " . $connect->connect_error);
}

And finally, how the connection appears to me in WorkBench:

Enter image description here

python – Django models: retrieving database data in a for loop

This code stops my Django project on every run:

def list(self, request):
        queryset = self.get_queryset()
        serializer = self.get_serializer(queryset, many=True)
        for element in serializer.data:
            element("data") = Device.objects.get(pk=element("device_id")).get_device_data(
                data_types="__all__", is_last_value=True
            )

        return Response(serializer.data)

This is a basic GET request function for django-rest-framework,

self.get_queryset() is a standard Django method
self.get_serializer() generates a view (in this case the device objects are listed)

get_device_data sends a request to an API to retrieve data associated with the device:

def get_device_data(
    devices: dict,
    is_last_value: bool,
    data_types: list = None,
    from_timestamp: datetime = None,
    to_timestamp: datetime = None,
    aggregate_period_name: str = None,
    aggregate_operation_name: str = None,
    decimal_places: int = None,
):
    """
        Arguments:
            - devices: {device1_reference: device1_name, device2_reference: device2_name, ...}
            - is_last_value: True | False
            - data_types: ("temperature", "humidity", ...) or ("__all__")
            - from_timestamp: datetime or None
            - to_timestamp: datetime or None
            - aggregate_period_name: str or None
            - aggregate_operation_name: str or None

        Get data of all devices or devices specified.

        Return example:

            "graph_data": (
                {
                    "device_reference": "740bd079-51fd-499f-8e72-bb545f22456
                    "device_name": "Capteur 2",
                    "data_type": "humidity",
                    "data_points": (
                        {
                            "timestamp": 1532072700,
                            "value": "82"
                        }
                    )
                },
            )
    """

    # All values are optional
    if not devices:
        return ()

    if isinstance(from_timestamp, datetime):
        from_timestamp = from_timestamp.isoformat()
    if isinstance(to_timestamp, datetime):
        to_timestamp = to_timestamp.isoformat()

    data_dict = {
        "devices": devices,
        "is_last_value": is_last_value,
        "data_types": data_types,
        "from_timestamp": from_timestamp,
        "to_timestamp": to_timestamp,
        "aggregate_period_name": aggregate_period_name,
        "aggregate_operation_name": aggregate_operation_name,
        "decimal_places": decimal_places,
    }

    # Exceptions are not caught to help with the debugging
    startup_response = requests.post(
        f"{settings.STARTUP_API_URL}/iot_rocket/device_data",
        data=json.dumps(data_dict),
        headers={"content-type": "application/json"},
    )
    startup_response = startup_response.json()
    return startup_response

What would be a more efficient way to achieve the same result?

PHP – problem with retrieving javascript page size

My script works as usual. When it reaches the bottom of the main page, it calls another script, in which it returns text and adds text at the bottom of the main page.
The problem is that after adding the text the page gets bigger and the script stops working. It's like he does not recalculate the size.

Script:

$ (document) .ready (function () {
var CurrentCurrent = $ (window) .scrollTop ();
var documentSize = $ (document) .height ();
var sizeWindow = $ (window) .height ();

$ (window) .scroll (function () {
Current position = $ (window) .scrollTop () + 50;
if (current position> = (documentSize – sizeWindow)) {
// alert ("End of document ->" + current position);
$ .ajax ({
url: & # 39; partoes / showmoreposts.php & # 39 ;, // PHP page that selects posts
Type: & # 39; POST & # 39 ;, Post Method, GET …
Data: & # 39; Limit = 10 & Offset = 0 & # 39 ;, your parameters
Success: Function (Data) {// Return Success Execute Function
$ (& # 39; middle & # 39;). append (date); // add the result to div #content
} // finish success
}); // finish Ajax
}
});

$ (window) .resize (function () {
Current position = $ (window) .scrollTop ();
documentSize = $ (document) .height ();
sizeWindow = $ (window) .height ();
});

});

on the showmoreposts page:

aaaaaaaaaaaaaaasasasas

";
?>